1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include "view/SlsToolTip.hxx"
27 #include "view/SlideSorterView.hxx"
28 #include "view/SlsLayouter.hxx"
29 #include "view/SlsTheme.hxx"
30 #include "sdpage.hxx"
31 #include "sdresid.hxx"
32 #include "glob.hrc"
33 #include <vcl/help.hxx>
34 
35 using ::rtl::OUString;
36 
37 namespace sd { namespace slidesorter { namespace view {
38 
ToolTip(SlideSorter & rSlideSorter)39 ToolTip::ToolTip (SlideSorter& rSlideSorter)
40 	: mrSlideSorter(rSlideSorter),
41 	  msDefaultHelpText(),
42 	  msCurrentHelpText(),
43 	  mnHelpWindowHandle(0),
44 	  maTimer()
45 {
46 	maTimer.SetTimeout(rSlideSorter.GetTheme()->GetIntegerValue(Theme::Integer_ToolTipDelay));
47 	maTimer.SetTimeoutHdl(LINK(this, ToolTip, DelayTrigger));
48 }
49 
50 
51 
52 
~ToolTip(void)53 ToolTip::~ToolTip (void)
54 {
55 	maTimer.Stop();
56 	Hide();
57 }
58 
59 
60 
61 
SetPage(const model::SharedPageDescriptor & rpDescriptor)62 void ToolTip::SetPage (const model::SharedPageDescriptor& rpDescriptor)
63 {
64 	if (mpDescriptor != rpDescriptor)
65 	{
66 		maTimer.Stop();
67 		Hide();
68 
69 		mpDescriptor = rpDescriptor;
70 
71 		if (mpDescriptor)
72 		{
73 			SdPage* pPage = mpDescriptor->GetPage();
74 			OUString sHelpText;
75 			if (pPage != NULL)
76 				sHelpText = pPage->GetName();
77 			else
78 			{
79 				OSL_ASSERT(mpDescriptor->GetPage() != NULL);
80 			}
81 			if (sHelpText.getLength() == 0)
82 			{
83 				sHelpText = String(SdResId(STR_PAGE));
84 				sHelpText += String::CreateFromInt32(mpDescriptor->GetPageIndex()+1);
85 			}
86 
87 			msDefaultHelpText = sHelpText;
88 			msCurrentHelpText = sHelpText;
89 			Show(false);
90 		}
91 		else
92 		{
93 			msDefaultHelpText = OUString();
94 			msCurrentHelpText = OUString();
95 		}
96 	}
97 }
98 
99 
100 
101 
ShowDefaultHelpText(const::rtl::OUString & rsHelpText)102 void ToolTip::ShowDefaultHelpText (const ::rtl::OUString& rsHelpText)
103 {
104 	if (msDefaultHelpText != rsHelpText)
105 	{
106 		const bool bIsVisible (Hide());
107 
108 		msDefaultHelpText = rsHelpText;
109 		msCurrentHelpText = rsHelpText;
110 
111 		Show(bIsVisible);
112 	}
113 }
114 
115 
116 
117 
ShowDefaultHelpText(void)118 void ToolTip::ShowDefaultHelpText (void)
119 {
120 	if (msCurrentHelpText != msDefaultHelpText)
121 	{
122 		const bool bIsVisible (Hide());
123 
124 		msCurrentHelpText = msDefaultHelpText;
125 
126 		Show(bIsVisible);
127 	}
128 }
129 
130 
131 
132 
ShowHelpText(const::rtl::OUString & rsHelpText)133 void ToolTip::ShowHelpText (const ::rtl::OUString& rsHelpText)
134 {
135 	if (msCurrentHelpText != rsHelpText)
136 	{
137 		const bool bIsVisible (Hide());
138 
139 		msCurrentHelpText = rsHelpText;
140 
141 		Show(bIsVisible);
142 	}
143 }
144 
145 
146 
147 
Show(const bool bNoDelay)148 void ToolTip::Show (const bool bNoDelay)
149 {
150 	if (bNoDelay)
151 		DoShow();
152 	else
153 		maTimer.Start();
154 }
155 
156 
157 
158 
DoShow(void)159 void ToolTip::DoShow (void)
160 {
161 	if (maTimer.IsActive())
162 	{
163 		// The delay timer is active. Wait for it to trigger the showing of
164 		// the tool tip.
165 		return;
166 	}
167 
168 	SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
169 	if (msCurrentHelpText.getLength()>0 && pWindow)
170 	{
171 		Rectangle aBox (
172 			mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
173 				mpDescriptor,
174 				PageObjectLayouter::Preview,
175 				PageObjectLayouter::WindowCoordinateSystem));
176 
177 		// Do not show the help text when the (lower edge of the ) preview
178 		// is not visible. The tool tip itself may still be outside the
179 		// window.
180 		if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
181 			return;
182 
183 		::Window* pParent (pWindow.get());
184 		while (pParent!=NULL && pParent->GetParent()!=NULL)
185 			pParent = pParent->GetParent();
186 		const Point aOffset (pWindow->GetWindowExtentsRelative(pParent).TopLeft());
187 
188 		// We do not know how high the tool tip will be but want its top
189 		// edge not its bottom to be at a specific position (a little below
190 		// the preview). Therefore we use a little trick and place the tool
191 		// tip at the top of a rectangle that is placed below the preview.
192 		aBox.Move(aOffset.X(), aOffset.Y() + aBox.GetHeight() + 3);
193 		mnHelpWindowHandle = Help::ShowTip(
194 			pWindow.get(),
195 			aBox,
196 			msCurrentHelpText,
197 			QUICKHELP_CENTER | QUICKHELP_TOP);
198 	}
199 }
200 
201 
202 
203 
Hide(void)204 bool ToolTip::Hide (void)
205 {
206 	if (mnHelpWindowHandle>0)
207 	{
208 		Help::HideTip(mnHelpWindowHandle);
209 		mnHelpWindowHandle = 0;
210 		return true;
211 	}
212 	else
213 		return false;
214 }
215 
216 
217 
218 
IMPL_LINK(ToolTip,DelayTrigger,void *,EMPTYARG)219 IMPL_LINK(ToolTip, DelayTrigger, void*, EMPTYARG)
220 {
221 	DoShow();
222 
223 	return 0;
224 }
225 
226 } } } // end of namespace ::sd::slidesorter::view
227