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->SetSettings( aAllSettings );
37  return nRet;
38 }
39 
40 bool 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  // is an id available, then call help with the id, otherwise
95  // use help-index
96  OUString aCommand = pMenu->GetItemCommand( nId );
97  OString aHelpId( pMenu->GetHelpId( nId ) );
98  if( aHelpId.isEmpty() )
99  aHelpId = OOO_HELP_INDEX;
100 
101  if ( !aCommand.isEmpty() )
102  pHelp->Start(aCommand, static_cast<vcl::Window*>(nullptr));
103  else
104  pHelp->Start(OStringToOUString(aHelpId, RTL_TEXTENCODING_UTF8), static_cast<vcl::Window*>(nullptr));
105  }
106  bDone = true;
107  }
108  return bDone;
109 }
110 
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OString GetHelpId(sal_uInt16 nItemId) const
Definition: menu.cxx:1134
#define OOO_HELP_INDEX
Definition: help.hxx:53
Definition: help.hxx:60
static Help * GetHelp()
Gets the application's help.
Definition: svapp.cxx:1317
sal_uIntPtr sal_uLong
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
sal_Int16 nId
virtual void SetSettings(const AllSettings &rSettings) override
HelpEventMode GetMode() const
Definition: event.hxx:192
OUString GetItemCommand(sal_uInt16 nItemId) const
Definition: menu.cxx:1047
const Point & GetMousePosPixel() const
Definition: event.hxx:191
sal_uInt16 nId
virtual bool Start(const OUString &rHelpId, const vcl::Window *pWindow)
Definition: help.cxx:53
sal_uLong GetTipTimeout() const
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
MenuItemList * GetItemList() const
Definition: menu.hxx:350
bool KeyboardActivated() const
Definition: event.hxx:193
static void ShowQuickHelp(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rHelpText, QuickHelpFlags nStyle=QuickHelpFlags::NONE)
Definition: help.cxx:178
OUString GetTipHelpText(sal_uInt16 nItemId) const
Definition: menu.cxx:1116
MenuItemData * GetDataFromPos(size_t nPos) const
Definition: menu.hxx:121
OUString GetHelpText(sal_uInt16 nItemId) const
Definition: menu.cxx:1103
Point Center() const
static void ShowBalloon(vcl::Window *pParent, const Point &rScreenPos, const tools::Rectangle &, const OUString &rHelpText)
Definition: help.cxx:155