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