1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
;
40 void MenuButton::ImplInit( Window
* pParent
, WinBits nStyle
)
42 if ( !(nStyle
& WB_NOTABSTOP
) )
45 PushButton::ImplInit( pParent
, nStyle
);
46 EnableRTL( Application::GetSettings().GetLayoutRTL() );
49 void MenuButton::ImplExecuteMenu()
56 Size aSize
= GetSizePixel();
57 Rectangle
aRect( aPos
, aSize
);
58 SetPressed( sal_True
);
60 mnCurItemId
= mpMenu
->Execute( this, aRect
, POPUPMENU_EXECUTE_DOWN
);
61 SetPressed( sal_False
);
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
) )
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()
117 IMPL_LINK_NOARG(MenuButton
, ImplMenuTimeoutHdl
)
119 // See if Button Tracking is still active, as it could've been cancelled earler
122 if ( !(GetStyle() & WB_NOPOINTERFOCUS
) )
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() )
142 mpMenuTimer
= new Timer
;
143 mpMenuTimer
->SetTimeoutHdl( LINK( this, MenuButton
, ImplMenuTimeoutHdl
) );
146 mpMenuTimer
->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
147 mpMenuTimer
->Start();
149 PushButton::MouseButtonDown( rMEvt
);
155 if ( PushButton::ImplHitTestPushButton( this, rMEvt
.GetPosPixel() ) )
157 if ( !(GetStyle() & WB_NOPOINTERFOCUS
) )
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() )
171 else if ( !(mnMenuMode
& MENUBUTTON_MENUMODE_TIMED
) &&
172 !aKeyCode
.GetModifier() &&
173 ((nCode
== KEY_RETURN
) || (nCode
== KEY_SPACE
)) )
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
198 void MenuButton::SetPopupMenu( PopupMenu
* pNewMenu
)
200 if (pNewMenu
== mpMenu
)
203 // FIXME: It's better to not inline this for 5.1; in 6.0 we can make it inline, however
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */