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 .
20 #include "menuwindow.hxx"
21 #include "menuitemlist.hxx"
23 #include <vcl/help.hxx>
24 #include <vcl/menu.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/window.hxx>
29 static sal_uLong
ImplChangeTipTimeout( sal_uLong nTimeout
, vcl::Window
*pWindow
)
31 AllSettings
aAllSettings( pWindow
->GetSettings() );
32 HelpSettings
aHelpSettings( aAllSettings
.GetHelpSettings() );
33 sal_uLong nRet
= aHelpSettings
.GetTipTimeout();
34 aHelpSettings
.SetTipTimeout( nTimeout
);
35 aAllSettings
.SetHelpSettings( aHelpSettings
);
36 pWindow
->SetSettings( aAllSettings
);
40 bool MenuWindow::ImplHandleHelpEvent(vcl::Window
* pMenuWindow
, Menu
* pMenu
, sal_uInt16 nHighlightedItem
,
41 const HelpEvent
& rHEvt
, const Rectangle
&rHighlightRect
)
49 if ( nHighlightedItem
!= ITEMPOS_INVALID
)
51 MenuItemData
* pItemData
= pMenu
->GetItemList()->GetDataFromPos( nHighlightedItem
);
56 if ( ( rHEvt
.GetMode() & HelpEventMode::BALLOON
) && pMenuWindow
)
59 if( rHEvt
.KeyboardActivated() )
60 aPos
= rHighlightRect
.Center();
62 aPos
= rHEvt
.GetMousePosPixel();
64 Rectangle
aRect( aPos
, Size() );
65 if (!pMenu
->GetHelpText(nId
).isEmpty())
66 Help::ShowBalloon( pMenuWindow
, aPos
, aRect
, pMenu
->GetHelpText( nId
) );
69 // give user a chance to read the full filename
70 sal_uLong oldTimeout
=ImplChangeTipTimeout( 60000, pMenuWindow
);
71 // call always, even when strlen==0 to correctly remove tip
72 Help::ShowQuickHelp( pMenuWindow
, aRect
, pMenu
->GetTipHelpText( nId
) );
73 ImplChangeTipTimeout( oldTimeout
, pMenuWindow
);
77 else if ( ( rHEvt
.GetMode() &HelpEventMode::QUICK
) && pMenuWindow
)
79 Point aPos
= rHEvt
.GetMousePosPixel();
80 Rectangle
aRect( aPos
, Size() );
81 // give user a chance to read the full filename
82 sal_uLong oldTimeout
=ImplChangeTipTimeout( 60000, pMenuWindow
);
83 // call always, even when strlen==0 to correctly remove tip
84 Help::ShowQuickHelp( pMenuWindow
, aRect
, pMenu
->GetTipHelpText( nId
) );
85 ImplChangeTipTimeout( oldTimeout
, pMenuWindow
);
88 else if ( rHEvt
.GetMode() & (HelpEventMode::CONTEXT
| HelpEventMode::EXTENDED
) )
90 // is help in the application selected
91 Help
* pHelp
= Application::GetHelp();
94 // is an id available, then call help with the id, otherwise
96 OUString aCommand
= pMenu
->GetItemCommand( nId
);
97 OString
aHelpId( pMenu
->GetHelpId( nId
) );
98 if( aHelpId
.isEmpty() )
99 aHelpId
= OOO_HELP_INDEX
;
101 if ( !aCommand
.isEmpty() )
102 pHelp
->Start( aCommand
, nullptr );
104 pHelp
->Start( OStringToOUString( aHelpId
, RTL_TEXTENCODING_UTF8
), nullptr );
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */