LibreOffice Module vcl (master) 1
menuwindow.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "menuwindow.hxx"
21#include "menuitemlist.hxx"
22
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>
28
30{
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->GetOutDev()->SetSettings( aAllSettings );
37 return nRet;
38}
39
40bool MenuWindow::ImplHandleHelpEvent(vcl::Window* pMenuWindow, Menu const * pMenu, sal_uInt16 nHighlightedItem,
41 const HelpEvent& rHEvt, const tools::Rectangle &rHighlightRect)
42{
43 if( ! pMenu )
44 return false;
45
46 bool bDone = false;
47 sal_uInt16 nId = 0;
48
49 if ( nHighlightedItem != ITEMPOS_INVALID )
50 {
51 MenuItemData* pItemData = pMenu->GetItemList()->GetDataFromPos( nHighlightedItem );
52 if ( pItemData )
53 nId = pItemData->nId;
54 }
55
56 if ( ( rHEvt.GetMode() & HelpEventMode::BALLOON ) && pMenuWindow )
57 {
58 Point aPos;
59 if( rHEvt.KeyboardActivated() )
60 aPos = rHighlightRect.Center();
61 else
62 aPos = rHEvt.GetMousePosPixel();
63
64 tools::Rectangle aRect( aPos, Size() );
65 if (!pMenu->GetHelpText(nId).isEmpty())
66 Help::ShowBalloon( pMenuWindow, aPos, aRect, pMenu->GetHelpText( nId ) );
67 else
68 {
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 );
74 }
75 bDone = true;
76 }
77 else if ( ( rHEvt.GetMode() &HelpEventMode::QUICK ) && pMenuWindow )
78 {
79 Point aPos = rHEvt.GetMousePosPixel();
80 tools::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 );
86 bDone = true;
87 }
88 else if ( rHEvt.GetMode() & HelpEventMode::CONTEXT )
89 {
90 // is help in the application selected
91 Help* pHelp = Application::GetHelp();
92 if ( pHelp )
93 {
94 // Check if there is a Help ID available, or else use
95 // the command URL
96 OUString aCommand = pMenu->GetItemCommand( nId );
97 OUString aHelpId;
98
99 // If no entry is selected, use the general menu Help ID
100 if (nId <= 0)
101 aHelpId = pMenu->GetHelpId();
102 else
103 aHelpId = pMenu->GetHelpId(nId);
104
105 if( aHelpId.isEmpty() )
106 aHelpId = OOO_HELP_INDEX;
107
108 if ( !aHelpId.isEmpty() )
109 pHelp->Start(aHelpId);
110 else
111 pHelp->Start(aCommand);
112 }
113 bDone = true;
114 }
115 return bDone;
116}
117
118/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetHelpSettings(const HelpSettings &rSet)
const HelpSettings & GetHelpSettings() const
static Help * GetHelp()
Gets the application's help.
Definition: svapp.cxx:1352
HelpEventMode GetMode() const
Definition: event.hxx:208
bool KeyboardActivated() const
Definition: event.hxx:209
const Point & GetMousePosPixel() const
Definition: event.hxx:207
void SetTipTimeout(sal_Int32 nTipTimeout)
sal_Int32 GetTipTimeout() const
Definition: help.hxx:61
virtual bool Start(const OUString &rHelpId, weld::Widget *pWidget=nullptr)
Definition: help.cxx:58
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
Definition: help.cxx:180
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
Definition: help.cxx:157
MenuItemData * GetDataFromPos(size_t nPos) const
static bool ImplHandleHelpEvent(vcl::Window *pMenuWindow, Menu const *pMenu, sal_uInt16 nHighlightedItem, const HelpEvent &rHEvt, const tools::Rectangle &rHighlightRect)
Show the appropriate help tooltip.
Definition: menuwindow.cxx:40
Definition: menu.hxx:116
OUString GetItemCommand(sal_uInt16 nItemId) const
Definition: menu.cxx:1063
OUString GetHelpId(sal_uInt16 nItemId) const
Definition: menu.cxx:1156
OUString GetHelpText(sal_uInt16 nItemId) const
Definition: menu.cxx:1125
MenuItemList * GetItemList() const
Definition: menu.hxx:350
OUString GetTipHelpText(sal_uInt16 nItemId) const
Definition: menu.cxx:1138
virtual void SetSettings(const AllSettings &rSettings)
Definition: outdev.cxx:215
constexpr Point Center() const
const AllSettings & GetSettings() const
Definition: window3.cxx:129
::OutputDevice const * GetOutDev() const
Definition: window.cxx:567
#define OOO_HELP_INDEX
Definition: help.hxx:53
constexpr auto ITEMPOS_INVALID
Invalid menu item id.
Definition: menu.hxx:100
static sal_uLong ImplChangeTipTimeout(sal_uLong nTimeout, vcl::Window *pWindow)
Definition: menuwindow.cxx:29
sal_Int16 nId
sal_uIntPtr sal_uLong
sal_uInt16 nId
OUString aCommand