19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
39f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file
59f62ea84SAndrew Rist * distributed with this work for additional information
69f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file
79f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at
109f62ea84SAndrew Rist *
119f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist *
139f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist * software distributed under the License is distributed on an
159f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist * KIND, either express or implied. See the License for the
179f62ea84SAndrew Rist * specific language governing permissions and limitations
189f62ea84SAndrew Rist * under the License.
199f62ea84SAndrew Rist *
209f62ea84SAndrew Rist *************************************************************/
219f62ea84SAndrew Rist
229f62ea84SAndrew 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
ImplInitMenuButtonData()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
ImplInit(Window * pParent,WinBits nStyle)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
ImplExecuteMenu()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
MenuButton(Window * pParent,WinBits nWinBits)91cdf0e10cSrcweir MenuButton::MenuButton( Window* pParent, WinBits nWinBits ) :
92cdf0e10cSrcweir PushButton( WINDOW_MENUBUTTON )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir ImplInitMenuButtonData();
95cdf0e10cSrcweir ImplInit( pParent, nWinBits );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
98cdf0e10cSrcweir // -----------------------------------------------------------------------
99cdf0e10cSrcweir
MenuButton(Window * pParent,const ResId & rResId)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
ImplLoadRes(const ResId & rResId)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
~MenuButton()131cdf0e10cSrcweir MenuButton::~MenuButton()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir if ( mpMenuTimer )
134cdf0e10cSrcweir delete mpMenuTimer;
135cdf0e10cSrcweir if ( mpOwnMenu )
136cdf0e10cSrcweir delete mpOwnMenu;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // -----------------------------------------------------------------------
140cdf0e10cSrcweir
IMPL_LINK(MenuButton,ImplMenuTimeoutHdl,Timer *,EMPTYARG)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
MouseButtonDown(const MouseEvent & rMEvt)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
164*c8d4a3f3STsutomu Uchino if ( ImplGetSymbolRect().IsEmpty() ||
165*c8d4a3f3STsutomu Uchino ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) &&
166*c8d4a3f3STsutomu Uchino rMEvt.GetPosPixel().X() < ImplGetSymbolRect().Left() ) )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir if ( !mpMenuTimer )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir mpMenuTimer = new Timer;
171cdf0e10cSrcweir mpMenuTimer->SetTimeoutHdl( LINK( this, MenuButton, ImplMenuTimeoutHdl ) );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir mpMenuTimer->SetTimeout( GetSettings().GetMouseSettings().GetActionDelay() );
175cdf0e10cSrcweir mpMenuTimer->Start();
176cdf0e10cSrcweir
177cdf0e10cSrcweir PushButton::MouseButtonDown( rMEvt );
178cdf0e10cSrcweir bExecute = false;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir if( bExecute )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir if ( PushButton::ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir if ( !(GetStyle() & WB_NOPOINTERFOCUS) )
186cdf0e10cSrcweir GrabFocus();
187cdf0e10cSrcweir ImplExecuteMenu();
188cdf0e10cSrcweir }
189cdf0e10cSrcweir }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir // -----------------------------------------------------------------------
193cdf0e10cSrcweir
KeyInput(const KeyEvent & rKEvt)194cdf0e10cSrcweir void MenuButton::KeyInput( const KeyEvent& rKEvt )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir KeyCode aKeyCode = rKEvt.GetKeyCode();
197cdf0e10cSrcweir sal_uInt16 nCode = aKeyCode.GetCode();
198cdf0e10cSrcweir if ( (nCode == KEY_DOWN) && aKeyCode.IsMod2() )
199cdf0e10cSrcweir ImplExecuteMenu();
200cdf0e10cSrcweir else if ( !(mnMenuMode & MENUBUTTON_MENUMODE_TIMED) &&
201cdf0e10cSrcweir !aKeyCode.GetModifier() &&
202cdf0e10cSrcweir ((nCode == KEY_RETURN) || (nCode == KEY_SPACE)) )
203cdf0e10cSrcweir ImplExecuteMenu();
204cdf0e10cSrcweir else
205cdf0e10cSrcweir PushButton::KeyInput( rKEvt );
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
208cdf0e10cSrcweir // -----------------------------------------------------------------------
209cdf0e10cSrcweir
Activate()210cdf0e10cSrcweir void MenuButton::Activate()
211cdf0e10cSrcweir {
212cdf0e10cSrcweir maActivateHdl.Call( this );
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir // -----------------------------------------------------------------------
216cdf0e10cSrcweir
Select()217cdf0e10cSrcweir void MenuButton::Select()
218cdf0e10cSrcweir {
219cdf0e10cSrcweir maSelectHdl.Call( this );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
222cdf0e10cSrcweir // -----------------------------------------------------------------------
223cdf0e10cSrcweir
SetMenuMode(sal_uInt16 nMode)224cdf0e10cSrcweir void MenuButton::SetMenuMode( sal_uInt16 nMode )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann
227cdf0e10cSrcweir // diese Funktion zur 6.0 inline werden
228cdf0e10cSrcweir mnMenuMode = nMode;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231cdf0e10cSrcweir // -----------------------------------------------------------------------
232cdf0e10cSrcweir
SetPopupMenu(PopupMenu * pNewMenu)233cdf0e10cSrcweir void MenuButton::SetPopupMenu( PopupMenu* pNewMenu )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir // Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann
236cdf0e10cSrcweir // diese Funktion zur 6.0 inline werden
237cdf0e10cSrcweir mpMenu = pNewMenu;
238cdf0e10cSrcweir }
239