1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: menubtn.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
37 #include <vcl/decoview.hxx>
38 #include <vcl/event.hxx>
39 #include <vcl/menu.hxx>
40 #include <vcl/timer.hxx>
41 #include <vcl/menubtn.hxx>
45 // =======================================================================
47 #define IMAGEBUTTON_BORDER_OFF1 11
48 #define IMAGEBUTTON_BORDER_OFF2 16
50 // =======================================================================
52 void MenuButton::ImplInitMenuButtonData()
54 mnDDStyle
= PUSHBUTTON_DROPDOWN_MENUBUTTON
;
63 // -----------------------------------------------------------------------
65 void MenuButton::ImplInit( Window
* pParent
, WinBits nStyle
)
67 if ( !(nStyle
& WB_NOTABSTOP
) )
70 PushButton::ImplInit( pParent
, nStyle
);
73 // -----------------------------------------------------------------------
75 void MenuButton::ImplExecuteMenu()
82 Size aSize
= GetSizePixel();
83 Rectangle
aRect( aPos
, aSize
);
84 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
85 if ( !((GetStyle() & (WB_RECTSTYLE
| WB_SMALLSTYLE
)) ||
86 !(rStyleSettings
.GetOptions() & STYLE_OPTION_MACSTYLE
)) )
95 mnCurItemId
= mpMenu
->Execute( this, aRect
, POPUPMENU_EXECUTE_DOWN
);
105 // -----------------------------------------------------------------------
107 MenuButton::MenuButton( Window
* pParent
, WinBits nWinBits
) :
108 PushButton( WINDOW_MENUBUTTON
)
110 ImplInitMenuButtonData();
111 ImplInit( pParent
, nWinBits
);
114 // -----------------------------------------------------------------------
116 MenuButton::MenuButton( Window
* pParent
, const ResId
& rResId
) :
117 PushButton( WINDOW_MENUBUTTON
)
119 ImplInitMenuButtonData();
120 rResId
.SetRT( RSC_MENUBUTTON
);
121 WinBits nStyle
= ImplInitRes( rResId
);
122 ImplInit( pParent
, nStyle
);
123 ImplLoadRes( rResId
);
125 if ( !(nStyle
& WB_HIDE
) )
129 // -----------------------------------------------------------------------
131 void MenuButton::ImplLoadRes( const ResId
& rResId
)
133 Control::ImplLoadRes( rResId
);
135 ULONG nObjMask
= ReadLongRes();
137 if ( RSCMENUBUTTON_MENU
& nObjMask
)
139 mpOwnMenu
= new PopupMenu( ResId( (RSHEADER_TYPE
*)GetClassRes(), *rResId
.GetResMgr() ) );
140 SetPopupMenu( mpOwnMenu
);
141 IncrementRes( GetObjSizeRes( (RSHEADER_TYPE
*)GetClassRes() ) );
145 // -----------------------------------------------------------------------
147 MenuButton::~MenuButton()
155 // -----------------------------------------------------------------------
157 IMPL_LINK( MenuButton
, ImplMenuTimeoutHdl
, Timer
*, EMPTYARG
)
159 // Abfragen, ob Button-Benutzung noch aktiv ist, da diese ja auch
160 // vorher abgebrochen wurden sein koennte
163 if ( !(GetStyle() & WB_NOPOINTERFOCUS
) )
171 // -----------------------------------------------------------------------
173 void MenuButton::MouseButtonDown( const MouseEvent
& rMEvt
)
175 if ( mnMenuMode
& MENUBUTTON_MENUMODE_TIMED
)
179 mpMenuTimer
= new Timer
;
180 mpMenuTimer
->SetTimeoutHdl( LINK( this, MenuButton
, ImplMenuTimeoutHdl
) );
183 mpMenuTimer
->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
184 mpMenuTimer
->Start();
186 PushButton::MouseButtonDown( rMEvt
);
190 if ( PushButton::ImplHitTestPushButton( this, rMEvt
.GetPosPixel() ) )
192 if ( !(GetStyle() & WB_NOPOINTERFOCUS
) )
199 // -----------------------------------------------------------------------
201 void MenuButton::KeyInput( const KeyEvent
& rKEvt
)
203 KeyCode aKeyCode
= rKEvt
.GetKeyCode();
204 USHORT nCode
= aKeyCode
.GetCode();
205 if ( (nCode
== KEY_DOWN
) && aKeyCode
.IsMod2() )
207 else if ( !(mnMenuMode
& MENUBUTTON_MENUMODE_TIMED
) &&
208 !aKeyCode
.GetModifier() &&
209 ((nCode
== KEY_RETURN
) || (nCode
== KEY_SPACE
)) )
212 PushButton::KeyInput( rKEvt
);
215 // -----------------------------------------------------------------------
217 void MenuButton::Activate()
219 maActivateHdl
.Call( this );
222 // -----------------------------------------------------------------------
224 void MenuButton::Select()
226 maSelectHdl
.Call( this );
229 // -----------------------------------------------------------------------
231 void MenuButton::SetMenuMode( USHORT nMode
)
233 // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann
234 // diese Funktion zur 6.0 inline werden
238 // -----------------------------------------------------------------------
240 void MenuButton::SetPopupMenu( PopupMenu
* pNewMenu
)
242 // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann
243 // diese Funktion zur 6.0 inline werden