update dev300-m58
[ooovba.git] / vcl / source / control / menubtn.cxx
blobed4b7e3a8a76248bac9e5e59004a296f39dcc82d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: menubtn.cxx,v $
10 * $Revision: 1.10 $
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"
34 #ifndef _SV_RC_H
35 #include <tools/rc.h>
36 #endif
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;
56 mpMenuTimer = NULL;
57 mpMenu = NULL;
58 mpOwnMenu = NULL;
59 mnCurItemId = 0;
60 mnMenuMode = 0;
63 // -----------------------------------------------------------------------
65 void MenuButton::ImplInit( Window* pParent, WinBits nStyle )
67 if ( !(nStyle & WB_NOTABSTOP) )
68 nStyle |= WB_TABSTOP;
70 PushButton::ImplInit( pParent, nStyle );
73 // -----------------------------------------------------------------------
75 void MenuButton::ImplExecuteMenu()
77 Activate();
79 if ( mpMenu )
81 Point aPos( 0, 1 );
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)) )
88 aRect.Left() += 2;
89 aRect.Top() += 2;
90 aRect.Right() -= 2;
91 aRect.Bottom() -= 2;
93 SetPressed( TRUE );
94 EndSelection();
95 mnCurItemId = mpMenu->Execute( this, aRect, POPUPMENU_EXECUTE_DOWN );
96 SetPressed( FALSE );
97 if ( mnCurItemId )
99 Select();
100 mnCurItemId = 0;
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) )
126 Show();
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()
149 if ( mpMenuTimer )
150 delete mpMenuTimer;
151 if ( mpOwnMenu )
152 delete mpOwnMenu;
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
161 if ( IsTracking() )
163 if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
164 GrabFocus();
165 ImplExecuteMenu();
168 return 0;
171 // -----------------------------------------------------------------------
173 void MenuButton::MouseButtonDown( const MouseEvent& rMEvt )
175 if ( mnMenuMode & MENUBUTTON_MENUMODE_TIMED )
177 if ( !mpMenuTimer )
179 mpMenuTimer = new Timer;
180 mpMenuTimer->SetTimeoutHdl( LINK( this, MenuButton, ImplMenuTimeoutHdl ) );
183 mpMenuTimer->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
184 mpMenuTimer->Start();
186 PushButton::MouseButtonDown( rMEvt );
188 else
190 if ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) )
192 if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
193 GrabFocus();
194 ImplExecuteMenu();
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() )
206 ImplExecuteMenu();
207 else if ( !(mnMenuMode & MENUBUTTON_MENUMODE_TIMED) &&
208 !aKeyCode.GetModifier() &&
209 ((nCode == KEY_RETURN) || (nCode == KEY_SPACE)) )
210 ImplExecuteMenu();
211 else
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
235 mnMenuMode = nMode;
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
244 mpMenu = pNewMenu;