1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _SV_RC_H 28cdf0e10cSrcweir #include <tools/rc.h> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #include <vcl/decoview.hxx> 31cdf0e10cSrcweir #include <vcl/event.hxx> 32cdf0e10cSrcweir #include <vcl/menu.hxx> 33cdf0e10cSrcweir #include <vcl/timer.hxx> 34cdf0e10cSrcweir #include <vcl/menubtn.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweir // ======================================================================= 39cdf0e10cSrcweir 40cdf0e10cSrcweir #define IMAGEBUTTON_BORDER_OFF1 11 41cdf0e10cSrcweir #define IMAGEBUTTON_BORDER_OFF2 16 42cdf0e10cSrcweir 43cdf0e10cSrcweir // ======================================================================= 44cdf0e10cSrcweir 45cdf0e10cSrcweir void MenuButton::ImplInitMenuButtonData() 46cdf0e10cSrcweir { 47cdf0e10cSrcweir mnDDStyle = PUSHBUTTON_DROPDOWN_MENUBUTTON; 48cdf0e10cSrcweir 49cdf0e10cSrcweir mpMenuTimer = NULL; 50cdf0e10cSrcweir mpMenu = NULL; 51cdf0e10cSrcweir mpOwnMenu = NULL; 52cdf0e10cSrcweir mnCurItemId = 0; 53cdf0e10cSrcweir mnMenuMode = 0; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ----------------------------------------------------------------------- 57cdf0e10cSrcweir 58cdf0e10cSrcweir void MenuButton::ImplInit( Window* pParent, WinBits nStyle ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir if ( !(nStyle & WB_NOTABSTOP) ) 61cdf0e10cSrcweir nStyle |= WB_TABSTOP; 62cdf0e10cSrcweir 63cdf0e10cSrcweir PushButton::ImplInit( pParent, nStyle ); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir // ----------------------------------------------------------------------- 67cdf0e10cSrcweir 68cdf0e10cSrcweir void MenuButton::ImplExecuteMenu() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir Activate(); 71cdf0e10cSrcweir 72cdf0e10cSrcweir if ( mpMenu ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir Point aPos( 0, 1 ); 75cdf0e10cSrcweir Size aSize = GetSizePixel(); 76cdf0e10cSrcweir Rectangle aRect( aPos, aSize ); 77cdf0e10cSrcweir SetPressed( sal_True ); 78cdf0e10cSrcweir EndSelection(); 79cdf0e10cSrcweir mnCurItemId = mpMenu->Execute( this, aRect, POPUPMENU_EXECUTE_DOWN ); 80cdf0e10cSrcweir SetPressed( sal_False ); 81cdf0e10cSrcweir if ( mnCurItemId ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir Select(); 84cdf0e10cSrcweir mnCurItemId = 0; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir // ----------------------------------------------------------------------- 90cdf0e10cSrcweir 91cdf0e10cSrcweir MenuButton::MenuButton( Window* pParent, WinBits nWinBits ) : 92cdf0e10cSrcweir PushButton( WINDOW_MENUBUTTON ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir ImplInitMenuButtonData(); 95cdf0e10cSrcweir ImplInit( pParent, nWinBits ); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ----------------------------------------------------------------------- 99cdf0e10cSrcweir 100cdf0e10cSrcweir MenuButton::MenuButton( Window* pParent, const ResId& rResId ) : 101cdf0e10cSrcweir PushButton( WINDOW_MENUBUTTON ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir ImplInitMenuButtonData(); 104cdf0e10cSrcweir rResId.SetRT( RSC_MENUBUTTON ); 105cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 106cdf0e10cSrcweir ImplInit( pParent, nStyle ); 107cdf0e10cSrcweir ImplLoadRes( rResId ); 108cdf0e10cSrcweir 109cdf0e10cSrcweir if ( !(nStyle & WB_HIDE) ) 110cdf0e10cSrcweir Show(); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // ----------------------------------------------------------------------- 114cdf0e10cSrcweir 115cdf0e10cSrcweir void MenuButton::ImplLoadRes( const ResId& rResId ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir Control::ImplLoadRes( rResId ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir sal_uLong nObjMask = ReadLongRes(); 120cdf0e10cSrcweir 121cdf0e10cSrcweir if ( RSCMENUBUTTON_MENU & nObjMask ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir mpOwnMenu = new PopupMenu( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) ); 124cdf0e10cSrcweir SetPopupMenu( mpOwnMenu ); 125cdf0e10cSrcweir IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) ); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir // ----------------------------------------------------------------------- 130cdf0e10cSrcweir 131cdf0e10cSrcweir MenuButton::~MenuButton() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir if ( mpMenuTimer ) 134cdf0e10cSrcweir delete mpMenuTimer; 135cdf0e10cSrcweir if ( mpOwnMenu ) 136cdf0e10cSrcweir delete mpOwnMenu; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir // ----------------------------------------------------------------------- 140cdf0e10cSrcweir 141cdf0e10cSrcweir IMPL_LINK( MenuButton, ImplMenuTimeoutHdl, Timer*, EMPTYARG ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir // Abfragen, ob Button-Benutzung noch aktiv ist, da diese ja auch 144cdf0e10cSrcweir // vorher abgebrochen wurden sein koennte 145cdf0e10cSrcweir if ( IsTracking() ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir if ( !(GetStyle() & WB_NOPOINTERFOCUS) ) 148cdf0e10cSrcweir GrabFocus(); 149cdf0e10cSrcweir ImplExecuteMenu(); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir return 0; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir // ----------------------------------------------------------------------- 156cdf0e10cSrcweir 157cdf0e10cSrcweir void MenuButton::MouseButtonDown( const MouseEvent& rMEvt ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir bool bExecute = true; 160cdf0e10cSrcweir if ( mnMenuMode & MENUBUTTON_MENUMODE_TIMED ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir // if the separated dropdown symbol is hit, 163cdf0e10cSrcweir // execute the popup immediately 164cdf0e10cSrcweir if( ! ImplGetSymbolRect().IsInside( rMEvt.GetPosPixel() ) ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir if ( !mpMenuTimer ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir mpMenuTimer = new Timer; 169cdf0e10cSrcweir mpMenuTimer->SetTimeoutHdl( LINK( this, MenuButton, ImplMenuTimeoutHdl ) ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir mpMenuTimer->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() ); 173cdf0e10cSrcweir mpMenuTimer->Start(); 174cdf0e10cSrcweir 175cdf0e10cSrcweir PushButton::MouseButtonDown( rMEvt ); 176cdf0e10cSrcweir bExecute = false; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir if( bExecute ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir if ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir if ( !(GetStyle() & WB_NOPOINTERFOCUS) ) 184cdf0e10cSrcweir GrabFocus(); 185cdf0e10cSrcweir ImplExecuteMenu(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir // ----------------------------------------------------------------------- 191cdf0e10cSrcweir 192cdf0e10cSrcweir void MenuButton::KeyInput( const KeyEvent& rKEvt ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir KeyCode aKeyCode = rKEvt.GetKeyCode(); 195cdf0e10cSrcweir sal_uInt16 nCode = aKeyCode.GetCode(); 196cdf0e10cSrcweir if ( (nCode == KEY_DOWN) && aKeyCode.IsMod2() ) 197cdf0e10cSrcweir ImplExecuteMenu(); 198cdf0e10cSrcweir else if ( !(mnMenuMode & MENUBUTTON_MENUMODE_TIMED) && 199cdf0e10cSrcweir !aKeyCode.GetModifier() && 200cdf0e10cSrcweir ((nCode == KEY_RETURN) || (nCode == KEY_SPACE)) ) 201cdf0e10cSrcweir ImplExecuteMenu(); 202cdf0e10cSrcweir else 203cdf0e10cSrcweir PushButton::KeyInput( rKEvt ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // ----------------------------------------------------------------------- 207cdf0e10cSrcweir 208cdf0e10cSrcweir void MenuButton::Activate() 209cdf0e10cSrcweir { 210cdf0e10cSrcweir maActivateHdl.Call( this ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir // ----------------------------------------------------------------------- 214cdf0e10cSrcweir 215cdf0e10cSrcweir void MenuButton::Select() 216cdf0e10cSrcweir { 217cdf0e10cSrcweir maSelectHdl.Call( this ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir // ----------------------------------------------------------------------- 221cdf0e10cSrcweir 222cdf0e10cSrcweir void MenuButton::SetMenuMode( sal_uInt16 nMode ) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann 225cdf0e10cSrcweir // diese Funktion zur 6.0 inline werden 226cdf0e10cSrcweir mnMenuMode = nMode; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir // ----------------------------------------------------------------------- 230cdf0e10cSrcweir 231cdf0e10cSrcweir void MenuButton::SetPopupMenu( PopupMenu* pNewMenu ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann 234cdf0e10cSrcweir // diese Funktion zur 6.0 inline werden 235cdf0e10cSrcweir mpMenu = pNewMenu; 236cdf0e10cSrcweir } 237