xref: /AOO41X/main/sd/source/ui/slidesorter/view/SlsToolTip.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_sd.hxx"
29 
30 #include "view/SlsToolTip.hxx"
31 #include "view/SlideSorterView.hxx"
32 #include "view/SlsLayouter.hxx"
33 #include "view/SlsTheme.hxx"
34 #include "sdpage.hxx"
35 #include "sdresid.hxx"
36 #include "glob.hrc"
37 #include <vcl/help.hxx>
38 
39 using ::rtl::OUString;
40 
41 namespace sd { namespace slidesorter { namespace view {
42 
43 ToolTip::ToolTip (SlideSorter& rSlideSorter)
44     : mrSlideSorter(rSlideSorter),
45       msDefaultHelpText(),
46       msCurrentHelpText(),
47       mnHelpWindowHandle(0),
48       maTimer()
49 {
50     maTimer.SetTimeout(rSlideSorter.GetTheme()->GetIntegerValue(Theme::Integer_ToolTipDelay));
51     maTimer.SetTimeoutHdl(LINK(this, ToolTip, DelayTrigger));
52 }
53 
54 
55 
56 
57 ToolTip::~ToolTip (void)
58 {
59     maTimer.Stop();
60     Hide();
61 }
62 
63 
64 
65 
66 void ToolTip::SetPage (const model::SharedPageDescriptor& rpDescriptor)
67 {
68     if (mpDescriptor != rpDescriptor)
69     {
70         maTimer.Stop();
71         Hide();
72 
73         mpDescriptor = rpDescriptor;
74 
75         if (mpDescriptor)
76         {
77             SdPage* pPage = mpDescriptor->GetPage();
78             OUString sHelpText;
79             if (pPage != NULL)
80                 sHelpText = pPage->GetName();
81             else
82             {
83                 OSL_ASSERT(mpDescriptor->GetPage() != NULL);
84             }
85             if (sHelpText.getLength() == 0)
86             {
87                 sHelpText = String(SdResId(STR_PAGE));
88                 sHelpText += String::CreateFromInt32(mpDescriptor->GetPageIndex()+1);
89             }
90 
91             msDefaultHelpText = sHelpText;
92             msCurrentHelpText = sHelpText;
93             Show(false);
94         }
95         else
96         {
97             msDefaultHelpText = OUString();
98             msCurrentHelpText = OUString();
99         }
100     }
101 }
102 
103 
104 
105 
106 void ToolTip::ShowDefaultHelpText (const ::rtl::OUString& rsHelpText)
107 {
108     if (msDefaultHelpText != rsHelpText)
109     {
110         const bool bIsVisible (Hide());
111 
112         msDefaultHelpText = rsHelpText;
113         msCurrentHelpText = rsHelpText;
114 
115         Show(bIsVisible);
116     }
117 }
118 
119 
120 
121 
122 void ToolTip::ShowDefaultHelpText (void)
123 {
124     if (msCurrentHelpText != msDefaultHelpText)
125     {
126         const bool bIsVisible (Hide());
127 
128         msCurrentHelpText = msDefaultHelpText;
129 
130         Show(bIsVisible);
131     }
132 }
133 
134 
135 
136 
137 void ToolTip::ShowHelpText (const ::rtl::OUString& rsHelpText)
138 {
139     if (msCurrentHelpText != rsHelpText)
140     {
141         const bool bIsVisible (Hide());
142 
143         msCurrentHelpText = rsHelpText;
144 
145         Show(bIsVisible);
146     }
147 }
148 
149 
150 
151 
152 void ToolTip::Show (const bool bNoDelay)
153 {
154     if (bNoDelay)
155         DoShow();
156     else
157         maTimer.Start();
158 }
159 
160 
161 
162 
163 void ToolTip::DoShow (void)
164 {
165     if (maTimer.IsActive())
166     {
167         // The delay timer is active.  Wait for it to trigger the showing of
168         // the tool tip.
169         return;
170     }
171 
172     SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
173     if (msCurrentHelpText.getLength()>0 && pWindow)
174     {
175         Rectangle aBox (
176             mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
177                 mpDescriptor,
178                 PageObjectLayouter::Preview,
179                 PageObjectLayouter::WindowCoordinateSystem));
180 
181         // Do not show the help text when the (lower edge of the ) preview
182         // is not visible.  The tool tip itself may still be outside the
183         // window.
184         if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
185             return;
186 
187         ::Window* pParent (pWindow.get());
188         while (pParent!=NULL && pParent->GetParent()!=NULL)
189             pParent = pParent->GetParent();
190         const Point aOffset (pWindow->GetWindowExtentsRelative(pParent).TopLeft());
191 
192         // We do not know how high the tool tip will be but want its top
193         // edge not its bottom to be at a specific position (a little below
194         // the preview).  Therefore we use a little trick and place the tool
195         // tip at the top of a rectangle that is placed below the preview.
196         aBox.Move(aOffset.X(), aOffset.Y() + aBox.GetHeight() + 3);
197         mnHelpWindowHandle = Help::ShowTip(
198             pWindow.get(),
199             aBox,
200             msCurrentHelpText,
201             QUICKHELP_CENTER | QUICKHELP_TOP);
202     }
203 }
204 
205 
206 
207 
208 bool ToolTip::Hide (void)
209 {
210     if (mnHelpWindowHandle>0)
211     {
212         Help::HideTip(mnHelpWindowHandle);
213         mnHelpWindowHandle = 0;
214         return true;
215     }
216     else
217         return false;
218 }
219 
220 
221 
222 
223 IMPL_LINK(ToolTip, DelayTrigger, void*, EMPTYARG)
224 {
225     DoShow();
226 
227     return 0;
228 }
229 
230 } } } // end of namespace ::sd::slidesorter::view
231