fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / vcl / source / control / menubtn.cxx
blob0fed804c9b21f1e42748b6166ff807f1b4aecc10
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
29 void MenuButton::ImplInitMenuButtonData()
31 mnDDStyle = PUSHBUTTON_DROPDOWN_MENUBUTTON;
33 mpMenuTimer = NULL;
34 mpMenu = NULL;
35 mpOwnMenu = NULL;
36 mnCurItemId = 0;
37 mnMenuMode = 0;
40 void MenuButton::ImplInit( Window* pParent, WinBits nStyle )
42 if ( !(nStyle & WB_NOTABSTOP) )
43 nStyle |= WB_TABSTOP;
45 PushButton::ImplInit( pParent, nStyle );
46 EnableRTL( Application::GetSettings().GetLayoutRTL() );
49 void MenuButton::ImplExecuteMenu()
51 Activate();
53 if ( mpMenu )
55 Point aPos( 0, 1 );
56 Size aSize = GetSizePixel();
57 Rectangle aRect( aPos, aSize );
58 SetPressed( sal_True );
59 EndSelection();
60 mnCurItemId = mpMenu->Execute( this, aRect, POPUPMENU_EXECUTE_DOWN );
61 SetPressed( sal_False );
62 if ( mnCurItemId )
64 Select();
65 mnCurItemId = 0;
70 OString MenuButton::GetCurItemIdent() const
72 return (mnCurItemId && mpMenu) ?
73 mpMenu->GetItemIdent(mnCurItemId) : OString();
77 MenuButton::MenuButton( Window* pParent, WinBits nWinBits )
78 : PushButton( WINDOW_MENUBUTTON )
80 ImplInitMenuButtonData();
81 ImplInit( pParent, nWinBits );
84 MenuButton::MenuButton( Window* pParent, const ResId& rResId )
85 : PushButton( WINDOW_MENUBUTTON )
87 ImplInitMenuButtonData();
88 rResId.SetRT( RSC_MENUBUTTON );
89 WinBits nStyle = ImplInitRes( rResId );
90 ImplInit( pParent, nStyle );
91 ImplLoadRes( rResId );
93 if ( !(nStyle & WB_HIDE) )
94 Show();
97 void MenuButton::ImplLoadRes( const ResId& rResId )
99 Control::ImplLoadRes( rResId );
101 sal_uLong nObjMask = ReadLongRes();
103 if ( RSCMENUBUTTON_MENU & nObjMask )
105 mpOwnMenu = new PopupMenu( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
106 SetPopupMenu( mpOwnMenu );
107 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
111 MenuButton::~MenuButton()
113 delete mpMenuTimer;
114 delete mpOwnMenu;
117 IMPL_LINK_NOARG(MenuButton, ImplMenuTimeoutHdl)
119 // See if Button Tracking is still active, as it could've been cancelled earler
120 if ( IsTracking() )
122 if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
123 GrabFocus();
124 ImplExecuteMenu();
127 return 0;
131 void MenuButton::MouseButtonDown( const MouseEvent& rMEvt )
133 bool bExecute = true;
134 if ( mnMenuMode & MENUBUTTON_MENUMODE_TIMED )
136 // If the separated dropdown symbol is not hit, delay the popup execution
137 if( mnDDStyle != PUSHBUTTON_DROPDOWN_MENUBUTTON || // no separator at all
138 rMEvt.GetPosPixel().X() <= ImplGetSeparatorX() )
140 if ( !mpMenuTimer )
142 mpMenuTimer = new Timer;
143 mpMenuTimer->SetTimeoutHdl( LINK( this, MenuButton, ImplMenuTimeoutHdl ) );
146 mpMenuTimer->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
147 mpMenuTimer->Start();
149 PushButton::MouseButtonDown( rMEvt );
150 bExecute = false;
153 if( bExecute )
155 if ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) )
157 if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
158 GrabFocus();
159 ImplExecuteMenu();
165 void MenuButton::KeyInput( const KeyEvent& rKEvt )
167 KeyCode aKeyCode = rKEvt.GetKeyCode();
168 sal_uInt16 nCode = aKeyCode.GetCode();
169 if ( (nCode == KEY_DOWN) && aKeyCode.IsMod2() )
170 ImplExecuteMenu();
171 else if ( !(mnMenuMode & MENUBUTTON_MENUMODE_TIMED) &&
172 !aKeyCode.GetModifier() &&
173 ((nCode == KEY_RETURN) || (nCode == KEY_SPACE)) )
174 ImplExecuteMenu();
175 else
176 PushButton::KeyInput( rKEvt );
180 void MenuButton::Activate()
182 maActivateHdl.Call( this );
186 void MenuButton::Select()
188 maSelectHdl.Call( this );
192 void MenuButton::SetMenuMode( sal_uInt16 nMode )
194 // FIXME: It's better to not inline this for 5.1; in 6.0 we can make it inline, however
195 mnMenuMode = nMode;
198 void MenuButton::SetPopupMenu( PopupMenu* pNewMenu )
200 if (pNewMenu == mpMenu)
201 return;
203 // FIXME: It's better to not inline this for 5.1; in 6.0 we can make it inline, however
204 mpMenu = pNewMenu;
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */