Line data Source code
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 "view/SlsToolTip.hxx"
21 : #include "view/SlideSorterView.hxx"
22 : #include "view/SlsLayouter.hxx"
23 : #include "view/SlsTheme.hxx"
24 : #include "sdpage.hxx"
25 : #include "sdresid.hxx"
26 : #include "glob.hrc"
27 :
28 : #include <vcl/settings.hxx>
29 : #include <vcl/help.hxx>
30 :
31 : namespace sd { namespace slidesorter { namespace view {
32 :
33 126 : ToolTip::ToolTip (SlideSorter& rSlideSorter)
34 : : mrSlideSorter(rSlideSorter),
35 : msCurrentHelpText(),
36 : mnHelpWindowHandle(0),
37 : maShowTimer(),
38 126 : maHiddenTimer()
39 : {
40 126 : SharedSdWindow window = rSlideSorter.GetContentWindow();
41 126 : const HelpSettings& rHelpSettings = window->GetSettings().GetHelpSettings();
42 126 : maShowTimer.SetTimeout(rHelpSettings.GetTipDelay());
43 126 : maShowTimer.SetTimeoutHdl(LINK(this, ToolTip, DelayTrigger));
44 126 : maHiddenTimer.SetTimeout(rHelpSettings.GetTipDelay());
45 126 : }
46 :
47 252 : ToolTip::~ToolTip (void)
48 : {
49 126 : maShowTimer.Stop();
50 126 : maHiddenTimer.Stop();
51 126 : Hide();
52 126 : }
53 :
54 0 : void ToolTip::SetPage (const model::SharedPageDescriptor& rpDescriptor)
55 : {
56 0 : if (mpDescriptor != rpDescriptor)
57 : {
58 0 : maShowTimer.Stop();
59 0 : bool bWasVisible = Hide();
60 :
61 0 : if (bWasVisible)
62 : {
63 0 : maHiddenTimer.Start();
64 : }
65 :
66 0 : mpDescriptor = rpDescriptor;
67 :
68 0 : if (mpDescriptor)
69 : {
70 0 : SdPage* pPage = mpDescriptor->GetPage();
71 0 : OUString sHelpText;
72 0 : if (pPage != NULL)
73 0 : sHelpText = pPage->GetName();
74 : else
75 : {
76 : OSL_ASSERT(mpDescriptor->GetPage() != NULL);
77 : }
78 0 : if (sHelpText.isEmpty())
79 : {
80 0 : sHelpText = SD_RESSTR(STR_PAGE);
81 0 : sHelpText += OUString::number(mpDescriptor->GetPageIndex()+1);
82 : }
83 :
84 0 : msCurrentHelpText = sHelpText;
85 : // show new tooltip immediately, if last one was recently hidden
86 0 : Show(maHiddenTimer.IsActive());
87 : }
88 : else
89 : {
90 0 : msCurrentHelpText = OUString();
91 : }
92 : }
93 0 : }
94 :
95 0 : void ToolTip::Show (const bool bNoDelay)
96 : {
97 0 : if (bNoDelay)
98 0 : DoShow();
99 : else
100 0 : maShowTimer.Start();
101 0 : }
102 :
103 0 : void ToolTip::DoShow (void)
104 : {
105 0 : if (maShowTimer.IsActive())
106 : {
107 : // The delay timer is active. Wait for it to trigger the showing of
108 : // the tool tip.
109 0 : return;
110 : }
111 :
112 0 : SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
113 0 : if (!msCurrentHelpText.isEmpty() && pWindow)
114 : {
115 : Rectangle aBox (
116 0 : mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
117 : mpDescriptor,
118 : PageObjectLayouter::Preview,
119 0 : PageObjectLayouter::WindowCoordinateSystem));
120 :
121 : // Do not show the help text when the (lower edge of the ) preview
122 : // is not visible. The tool tip itself may still be outside the
123 : // window.
124 0 : if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
125 0 : return;
126 :
127 0 : vcl::Window* pParent (pWindow.get());
128 0 : while (pParent!=NULL && pParent->GetParent()!=NULL)
129 0 : pParent = pParent->GetParent();
130 0 : const Point aOffset (pWindow->GetWindowExtentsRelative(pParent).TopLeft());
131 :
132 : // We do not know how high the tool tip will be but want its top
133 : // edge not its bottom to be at a specific position (a little below
134 : // the preview). Therefore we use a little trick and place the tool
135 : // tip at the top of a rectangle that is placed below the preview.
136 0 : aBox.Move(aOffset.X(), aOffset.Y() + aBox.GetHeight() + 3);
137 : mnHelpWindowHandle = Help::ShowTip(
138 0 : pWindow.get(),
139 : aBox,
140 : msCurrentHelpText,
141 0 : QUICKHELP_CENTER | QUICKHELP_TOP);
142 0 : }
143 : }
144 :
145 126 : bool ToolTip::Hide (void)
146 : {
147 126 : if (mnHelpWindowHandle>0)
148 : {
149 0 : Help::HideTip(mnHelpWindowHandle);
150 0 : mnHelpWindowHandle = 0;
151 0 : return true;
152 : }
153 : else
154 126 : return false;
155 : }
156 :
157 0 : IMPL_LINK_NOARG(ToolTip, DelayTrigger)
158 : {
159 0 : DoShow();
160 :
161 0 : return 0;
162 : }
163 :
164 114 : } } } // end of namespace ::sd::slidesorter::view
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|