LCOV - code coverage report
Current view: top level - vcl/source/control - menubtn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 101 28.7 %
Date: 2012-08-25 Functions: 6 16 37.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 104 7.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <tools/rc.h>
      31                 :            : #include <vcl/decoview.hxx>
      32                 :            : #include <vcl/event.hxx>
      33                 :            : #include <vcl/menu.hxx>
      34                 :            : #include <vcl/timer.hxx>
      35                 :            : #include <vcl/menubtn.hxx>
      36                 :            : #include <vcl/svapp.hxx>
      37                 :            : 
      38                 :            : // =======================================================================
      39                 :            : 
      40                 :         32 : void MenuButton::ImplInitMenuButtonData()
      41                 :            : {
      42                 :         32 :     mnDDStyle       = PUSHBUTTON_DROPDOWN_MENUBUTTON;
      43                 :            : 
      44                 :         32 :     mpMenuTimer     = NULL;
      45                 :         32 :     mpMenu          = NULL;
      46                 :         32 :     mpOwnMenu       = NULL;
      47                 :         32 :     mnCurItemId     = 0;
      48                 :         32 :     mnMenuMode      = 0;
      49                 :         32 : }
      50                 :            : 
      51                 :            : // -----------------------------------------------------------------------
      52                 :            : 
      53                 :         32 : void MenuButton::ImplInit( Window* pParent, WinBits nStyle )
      54                 :            : {
      55         [ +  - ]:         32 :     if ( !(nStyle & WB_NOTABSTOP) )
      56                 :         32 :         nStyle |= WB_TABSTOP;
      57                 :            : 
      58                 :         32 :     PushButton::ImplInit( pParent, nStyle );
      59                 :         32 :     EnableRTL( Application::GetSettings().GetLayoutRTL() );
      60                 :         32 : }
      61                 :            : 
      62                 :            : // -----------------------------------------------------------------------
      63                 :            : 
      64                 :          0 : void MenuButton::ImplExecuteMenu()
      65                 :            : {
      66                 :          0 :     Activate();
      67                 :            : 
      68         [ #  # ]:          0 :     if ( mpMenu )
      69                 :            :     {
      70                 :          0 :         Point aPos( 0, 1 );
      71         [ #  # ]:          0 :         Size aSize = GetSizePixel();
      72         [ #  # ]:          0 :         Rectangle aRect( aPos, aSize );
      73         [ #  # ]:          0 :         SetPressed( sal_True );
      74         [ #  # ]:          0 :         EndSelection();
      75         [ #  # ]:          0 :         mnCurItemId = mpMenu->Execute( this, aRect, POPUPMENU_EXECUTE_DOWN );
      76         [ #  # ]:          0 :         SetPressed( sal_False );
      77         [ #  # ]:          0 :         if ( mnCurItemId )
      78                 :            :         {
      79         [ #  # ]:          0 :             Select();
      80                 :          0 :             mnCurItemId = 0;
      81                 :            :         }
      82                 :            :     }
      83                 :          0 : }
      84                 :            : 
      85                 :            : // -----------------------------------------------------------------------
      86                 :            : 
      87                 :         32 : MenuButton::MenuButton( Window* pParent, WinBits nWinBits ) :
      88 [ +  - ][ +  - ]:         32 :     PushButton( WINDOW_MENUBUTTON )
                 [ +  - ]
      89                 :            : {
      90                 :         32 :     ImplInitMenuButtonData();
      91         [ +  - ]:         32 :     ImplInit( pParent, nWinBits );
      92                 :         32 : }
      93                 :            : 
      94                 :            : // -----------------------------------------------------------------------
      95                 :            : 
      96                 :          0 : MenuButton::MenuButton( Window* pParent, const ResId& rResId ) :
      97 [ #  # ][ #  # ]:          0 :     PushButton( WINDOW_MENUBUTTON )
                 [ #  # ]
      98                 :            : {
      99                 :          0 :     ImplInitMenuButtonData();
     100                 :          0 :     rResId.SetRT( RSC_MENUBUTTON );
     101         [ #  # ]:          0 :     WinBits nStyle = ImplInitRes( rResId );
     102         [ #  # ]:          0 :     ImplInit( pParent, nStyle );
     103         [ #  # ]:          0 :     ImplLoadRes( rResId );
     104                 :            : 
     105         [ #  # ]:          0 :     if ( !(nStyle & WB_HIDE) )
     106         [ #  # ]:          0 :         Show();
     107                 :          0 : }
     108                 :            : 
     109                 :            : // -----------------------------------------------------------------------
     110                 :            : 
     111                 :          0 : void MenuButton::ImplLoadRes( const ResId& rResId )
     112                 :            : {
     113                 :          0 :     Control::ImplLoadRes( rResId );
     114                 :            : 
     115                 :          0 :     sal_uLong nObjMask = ReadLongRes();
     116                 :            : 
     117         [ #  # ]:          0 :     if ( RSCMENUBUTTON_MENU & nObjMask )
     118                 :            :     {
     119 [ #  # ][ #  # ]:          0 :         mpOwnMenu = new PopupMenu( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
     120                 :          0 :         SetPopupMenu( mpOwnMenu );
     121                 :          0 :         IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
     122                 :            :     }
     123                 :          0 : }
     124                 :            : 
     125                 :            : // -----------------------------------------------------------------------
     126                 :            : 
     127                 :         26 : MenuButton::~MenuButton()
     128                 :            : {
     129 [ -  + ][ #  # ]:         26 :     delete mpMenuTimer;
     130 [ -  + ][ #  # ]:         26 :     delete mpOwnMenu;
     131         [ -  + ]:         26 : }
     132                 :            : 
     133                 :            : // -----------------------------------------------------------------------
     134                 :            : 
     135                 :          0 : IMPL_LINK_NOARG(MenuButton, ImplMenuTimeoutHdl)
     136                 :            : {
     137                 :            :     // Abfragen, ob Button-Benutzung noch aktiv ist, da diese ja auch
     138                 :            :     // vorher abgebrochen wurden sein koennte
     139         [ #  # ]:          0 :     if ( IsTracking() )
     140                 :            :     {
     141         [ #  # ]:          0 :         if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
     142                 :          0 :             GrabFocus();
     143                 :          0 :         ImplExecuteMenu();
     144                 :            :     }
     145                 :            : 
     146                 :          0 :     return 0;
     147                 :            : }
     148                 :            : 
     149                 :            : // -----------------------------------------------------------------------
     150                 :            : 
     151                 :          0 : void MenuButton::MouseButtonDown( const MouseEvent& rMEvt )
     152                 :            : {
     153                 :          0 :     bool bExecute = true;
     154         [ #  # ]:          0 :     if ( mnMenuMode & MENUBUTTON_MENUMODE_TIMED )
     155                 :            :     {
     156                 :            :         // if the separated dropdown symbol is not hit, delay the popup execution
     157   [ #  #  #  # ]:          0 :         if( mnDDStyle != PUSHBUTTON_DROPDOWN_MENUBUTTON || // no separator at all
                 [ #  # ]
     158                 :          0 :             rMEvt.GetPosPixel().X() <= ImplGetSeparatorX() )
     159                 :            :         {
     160         [ #  # ]:          0 :             if ( !mpMenuTimer )
     161                 :            :             {
     162         [ #  # ]:          0 :                 mpMenuTimer = new Timer;
     163                 :          0 :                 mpMenuTimer->SetTimeoutHdl( LINK( this, MenuButton, ImplMenuTimeoutHdl ) );
     164                 :            :             }
     165                 :            : 
     166                 :          0 :             mpMenuTimer->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
     167                 :          0 :             mpMenuTimer->Start();
     168                 :            : 
     169                 :          0 :             PushButton::MouseButtonDown( rMEvt );
     170                 :          0 :             bExecute = false;
     171                 :            :         }
     172                 :            :     }
     173         [ #  # ]:          0 :     if( bExecute )
     174                 :            :     {
     175         [ #  # ]:          0 :         if ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) )
     176                 :            :         {
     177         [ #  # ]:          0 :             if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
     178                 :          0 :                 GrabFocus();
     179                 :          0 :             ImplExecuteMenu();
     180                 :            :         }
     181                 :            :     }
     182                 :          0 : }
     183                 :            : 
     184                 :            : // -----------------------------------------------------------------------
     185                 :            : 
     186                 :          0 : void MenuButton::KeyInput( const KeyEvent& rKEvt )
     187                 :            : {
     188                 :          0 :     KeyCode aKeyCode = rKEvt.GetKeyCode();
     189                 :          0 :     sal_uInt16 nCode = aKeyCode.GetCode();
     190 [ #  # ][ #  # ]:          0 :     if ( (nCode == KEY_DOWN) && aKeyCode.IsMod2() )
                 [ #  # ]
     191         [ #  # ]:          0 :         ImplExecuteMenu();
     192   [ #  #  #  # ]:          0 :     else if ( !(mnMenuMode & MENUBUTTON_MENUMODE_TIMED) &&
         [ #  # ][ #  # ]
                 [ #  # ]
     193                 :          0 :               !aKeyCode.GetModifier() &&
     194                 :            :               ((nCode == KEY_RETURN) || (nCode == KEY_SPACE)) )
     195         [ #  # ]:          0 :         ImplExecuteMenu();
     196                 :            :     else
     197         [ #  # ]:          0 :         PushButton::KeyInput( rKEvt );
     198                 :          0 : }
     199                 :            : 
     200                 :            : // -----------------------------------------------------------------------
     201                 :            : 
     202                 :          0 : void MenuButton::Activate()
     203                 :            : {
     204                 :          0 :     maActivateHdl.Call( this );
     205                 :          0 : }
     206                 :            : 
     207                 :            : // -----------------------------------------------------------------------
     208                 :            : 
     209                 :          0 : void MenuButton::Select()
     210                 :            : {
     211                 :          0 :     maSelectHdl.Call( this );
     212                 :          0 : }
     213                 :            : 
     214                 :            : // -----------------------------------------------------------------------
     215                 :            : 
     216                 :          2 : void MenuButton::SetMenuMode( sal_uInt16 nMode )
     217                 :            : {
     218                 :            :     // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann
     219                 :            :     // diese Funktion zur 6.0 inline werden
     220                 :          2 :     mnMenuMode = nMode;
     221                 :          2 : }
     222                 :            : 
     223                 :            : // -----------------------------------------------------------------------
     224                 :            : 
     225                 :         30 : void MenuButton::SetPopupMenu( PopupMenu* pNewMenu )
     226                 :            : {
     227                 :            :     // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann
     228                 :            :     // diese Funktion zur 6.0 inline werden
     229                 :         30 :     mpMenu = pNewMenu;
     230                 :         30 : }
     231                 :            : 
     232                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10