Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / source / app / help.cxx
blob7014a790f789714ce76c92edefa7d2000549e80f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/string.hxx>
22 #include "tools/debug.hxx"
23 #include "tools/diagnose_ex.h"
24 #include "tools/time.hxx"
26 #include "vcl/window.hxx"
27 #include "vcl/event.hxx"
28 #include "vcl/svapp.hxx"
29 #include "vcl/wrkwin.hxx"
30 #include "vcl/help.hxx"
31 #include "vcl/settings.hxx"
33 #include "helpwin.hxx"
34 #include "svdata.hxx"
36 #define HELPWINSTYLE_QUICK 0
37 #define HELPWINSTYLE_BALLOON 1
39 #define HELPTEXTMARGIN_QUICK 3
40 #define HELPTEXTMARGIN_BALLOON 6
42 #define HELPDELAY_NORMAL 1
43 #define HELPDELAY_SHORT 2
44 #define HELPDELAY_NONE 3
46 #define HELPTEXTMAXLEN 150
48 Help::Help()
52 Help::~Help()
56 bool Help::Start( const OUString&, const vcl::Window* )
58 return false;
61 bool Help::SearchKeyword( const OUString& )
63 return false;
66 OUString Help::GetHelpText( const OUString&, const vcl::Window* )
68 return OUString();
71 void Help::EnableContextHelp()
73 ImplGetSVData()->maHelpData.mbContextHelp = true;
76 void Help::DisableContextHelp()
78 ImplGetSVData()->maHelpData.mbContextHelp = false;
81 bool Help::IsContextHelpEnabled()
83 return ImplGetSVData()->maHelpData.mbContextHelp;
86 void Help::EnableExtHelp()
88 ImplGetSVData()->maHelpData.mbExtHelp = true;
91 void Help::DisableExtHelp()
93 ImplGetSVData()->maHelpData.mbExtHelp = false;
96 bool Help::IsExtHelpEnabled()
98 return ImplGetSVData()->maHelpData.mbExtHelp;
101 bool Help::StartExtHelp()
103 ImplSVData* pSVData = ImplGetSVData();
105 if ( pSVData->maHelpData.mbExtHelp && !pSVData->maHelpData.mbExtHelpMode )
107 pSVData->maHelpData.mbExtHelpMode = true;
108 pSVData->maHelpData.mbOldBalloonMode = pSVData->maHelpData.mbBalloonHelp;
109 pSVData->maHelpData.mbBalloonHelp = true;
110 if ( pSVData->maWinData.mpAppWin )
111 pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
112 return true;
115 return false;
118 bool Help::EndExtHelp()
120 ImplSVData* pSVData = ImplGetSVData();
122 if ( pSVData->maHelpData.mbExtHelp && pSVData->maHelpData.mbExtHelpMode )
124 pSVData->maHelpData.mbExtHelpMode = false;
125 pSVData->maHelpData.mbBalloonHelp = pSVData->maHelpData.mbOldBalloonMode;
126 if ( pSVData->maWinData.mpAppWin )
127 pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
128 return true;
131 return false;
134 void Help::EnableBalloonHelp()
136 ImplGetSVData()->maHelpData.mbBalloonHelp = true;
139 void Help::DisableBalloonHelp()
141 ImplGetSVData()->maHelpData.mbBalloonHelp = false;
144 bool Help::IsBalloonHelpEnabled()
146 return ImplGetSVData()->maHelpData.mbBalloonHelp;
149 bool Help::ShowBalloon( vcl::Window* pParent,
150 const Point& rScreenPos,
151 const OUString& rHelpText )
153 ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, QuickHelpFlags::NONE,
154 rHelpText, OUString(), rScreenPos );
156 return true;
159 bool Help::ShowBalloon( vcl::Window* pParent,
160 const Point& rScreenPos, const Rectangle& rRect,
161 const OUString& rHelpText )
163 ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, QuickHelpFlags::NONE,
164 rHelpText, OUString(), rScreenPos, &rRect );
166 return true;
169 void Help::EnableQuickHelp()
171 ImplGetSVData()->maHelpData.mbQuickHelp = true;
174 void Help::DisableQuickHelp()
176 ImplGetSVData()->maHelpData.mbQuickHelp = false;
179 bool Help::IsQuickHelpEnabled()
181 return ImplGetSVData()->maHelpData.mbQuickHelp;
184 bool Help::ShowQuickHelp( vcl::Window* pParent,
185 const Rectangle& rScreenRect,
186 const OUString& rHelpText,
187 const OUString& rLongHelpText,
188 QuickHelpFlags nStyle )
190 ImplShowHelpWindow( pParent, HELPWINSTYLE_QUICK, nStyle,
191 rHelpText, rLongHelpText,
192 pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
193 return true;
196 void Help::HideBalloonAndQuickHelp()
198 HelpTextWindow const * pHelpWin = ImplGetSVData()->maHelpData.mpHelpWin;
199 bool const bIsVisible = ( pHelpWin != NULL ) && pHelpWin->IsVisible();
200 ImplDestroyHelpWindow( bIsVisible );
203 sal_uIntPtr Help::ShowTip( vcl::Window* pParent, const Rectangle& rScreenRect,
204 const OUString& rText, QuickHelpFlags nStyle )
206 sal_uInt16 nHelpWinStyle = ( nStyle & QuickHelpFlags::TipStyleBalloon ) ? HELPWINSTYLE_BALLOON : HELPWINSTYLE_QUICK;
207 VclPtrInstance<HelpTextWindow> pHelpWin( pParent, rText, nHelpWinStyle, nStyle );
209 sal_uIntPtr nId = reinterpret_cast< sal_uIntPtr >( pHelpWin.get() );
210 UpdateTip( nId, pParent, rScreenRect, rText );
212 pHelpWin->ShowHelp( HELPDELAY_NONE );
213 return nId;
216 void Help::UpdateTip( sal_uIntPtr nId, vcl::Window* pParent, const Rectangle& rScreenRect, const OUString& rText )
218 HelpTextWindow* pHelpWin = reinterpret_cast< HelpTextWindow* >( nId );
219 ENSURE_OR_RETURN_VOID( pHelpWin != NULL, "Help::UpdateTip: invalid ID!" );
221 Size aSz = pHelpWin->CalcOutSize();
222 pHelpWin->SetOutputSizePixel( aSz );
223 ImplSetHelpWindowPos( pHelpWin, pHelpWin->GetWinStyle(), pHelpWin->GetStyle(),
224 pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
226 pHelpWin->SetHelpText( rText );
227 pHelpWin->Invalidate();
230 void Help::HideTip( sal_uLong nId )
232 VclPtr<HelpTextWindow> pHelpWin = reinterpret_cast<HelpTextWindow*>(nId);
233 vcl::Window* pFrameWindow = pHelpWin->ImplGetFrameWindow();
234 pHelpWin->Hide();
235 // trigger update, so that a Paint is instantly triggered since we do not save the background
236 pFrameWindow->ImplUpdateAll();
237 pHelpWin.disposeAndClear();
238 ImplGetSVData()->maHelpData.mnLastHelpHideTime = tools::Time::GetSystemTicks();
241 HelpTextWindow::HelpTextWindow( vcl::Window* pParent, const OUString& rText, sal_uInt16 nHelpWinStyle, QuickHelpFlags nStyle ) :
242 FloatingWindow( pParent, WB_SYSTEMWINDOW|WB_TOOLTIPWIN ), // #105827# if we change the parent, mirroring will not work correctly when positioning this window
243 maHelpText( rText )
245 SetType( WINDOW_HELPTEXTWINDOW );
246 ImplSetMouseTransparent( true );
247 mnHelpWinStyle = nHelpWinStyle;
248 mnStyle = nStyle;
249 // on windows this will raise the application window, because help windows are system windows now
250 // EnableAlwaysOnTop();
251 EnableSaveBackground();
253 if( mnStyle & QuickHelpFlags::BiDiRtl )
255 ComplexTextLayoutMode nLayoutMode = GetLayoutMode();
256 nLayoutMode |= TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT;
257 SetLayoutMode( nLayoutMode );
259 SetHelpText( rText );
260 Window::SetHelpText( rText );
262 ImplSVData* pSVData = ImplGetSVData();
263 if ( pSVData->maHelpData.mbSetKeyboardHelp )
264 pSVData->maHelpData.mbKeyboardHelp = true;
266 const HelpSettings& rHelpSettings = pParent->GetSettings().GetHelpSettings();
267 maShowTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
268 maHideTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
269 maHideTimer.SetTimeout( rHelpSettings.GetTipTimeout() );
272 void HelpTextWindow::ApplySettings(vcl::RenderContext& rRenderContext)
274 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
275 SetPointFont(rRenderContext, rStyleSettings.GetHelpFont());
276 rRenderContext.SetTextColor(rStyleSettings.GetHelpTextColor());
277 rRenderContext.SetTextAlign(ALIGN_TOP);
279 if (rRenderContext.IsNativeControlSupported(CTRL_TOOLTIP, PART_ENTIRE_CONTROL))
281 EnableChildTransparentMode(true);
282 SetParentClipMode(PARENTCLIPMODE_NOCLIP);
283 SetPaintTransparent(true);
284 rRenderContext.SetBackground();
286 else
287 rRenderContext.SetBackground(Wallpaper(rStyleSettings.GetHelpColor()));
289 if (rStyleSettings.GetHelpColor().IsDark())
290 rRenderContext.SetLineColor(COL_WHITE);
291 else
292 rRenderContext.SetLineColor(COL_BLACK);
293 rRenderContext.SetFillColor();
296 HelpTextWindow::~HelpTextWindow()
298 disposeOnce();
301 void HelpTextWindow::dispose()
303 maShowTimer.Stop();
304 maHideTimer.Stop();
306 if( this == ImplGetSVData()->maHelpData.mpHelpWin )
307 ImplGetSVData()->maHelpData.mpHelpWin = NULL;
308 FloatingWindow::dispose();
311 void HelpTextWindow::SetHelpText( const OUString& rHelpText )
313 maHelpText = rHelpText;
314 if ( mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.getLength() < HELPTEXTMAXLEN)
316 Size aSize;
317 aSize.Height() = GetTextHeight();
318 if ( mnStyle & QuickHelpFlags::CtrlText )
319 aSize.Width() = GetCtrlTextWidth( maHelpText );
320 else
321 aSize.Width() = GetTextWidth( maHelpText );
322 maTextRect = Rectangle( Point( HELPTEXTMARGIN_QUICK, HELPTEXTMARGIN_QUICK ), aSize );
324 else // HELPWINSTYLE_BALLOON
326 Point aTmpPoint;
327 sal_Int32 nCharsInLine = 35 + ((maHelpText.getLength()/100)*5);
328 // average width to have all windows consistent
329 OUStringBuffer aBuf;
330 comphelper::string::padToLength(aBuf, nCharsInLine, 'x');
331 OUString aXXX = aBuf.makeStringAndClear();
332 long nWidth = GetTextWidth( aXXX );
333 Size aTmpSize( nWidth, 0x7FFFFFFF );
334 Rectangle aTry1( aTmpPoint, aTmpSize );
335 DrawTextFlags nDrawFlags = DrawTextFlags::MultiLine | DrawTextFlags::WordBreak |
336 DrawTextFlags::Left | DrawTextFlags::Top;
337 if ( mnStyle & QuickHelpFlags::CtrlText )
338 nDrawFlags |= DrawTextFlags::Mnemonic;
339 Rectangle aTextRect = GetTextRect( aTry1, maHelpText, nDrawFlags );
341 // get a better width later...
342 maTextRect = aTextRect;
344 // safety distance...
345 maTextRect.SetPos( Point( HELPTEXTMARGIN_BALLOON, HELPTEXTMARGIN_BALLOON ) );
348 Size aSize( CalcOutSize() );
349 SetOutputSizePixel( aSize );
352 void HelpTextWindow::ImplShow()
354 ImplDelData aDogTag( this );
355 Show( true, SHOW_NOACTIVATE );
356 if( !aDogTag.IsDead() )
357 Update();
360 void HelpTextWindow::Paint( vcl::RenderContext& rRenderContext, const Rectangle& )
362 // paint native background
363 bool bNativeOK = false;
364 if (rRenderContext.IsNativeControlSupported(CTRL_TOOLTIP, PART_ENTIRE_CONTROL))
366 // #i46472# workaround gcc3.3 temporary problem
367 Rectangle aCtrlRegion(Point(0, 0), GetOutputSizePixel());
368 ImplControlValue aControlValue;
369 bNativeOK = rRenderContext.DrawNativeControl(CTRL_TOOLTIP, PART_ENTIRE_CONTROL, aCtrlRegion,
370 ControlState::NONE, aControlValue, OUString());
373 // paint text
374 if (mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.getLength() < HELPTEXTMAXLEN)
376 if ( mnStyle & QuickHelpFlags::CtrlText )
377 rRenderContext.DrawCtrlText(maTextRect.TopLeft(), maHelpText);
378 else
379 rRenderContext.DrawText(maTextRect.TopLeft(), maHelpText);
381 else // HELPWINSTYLE_BALLOON
383 DrawTextFlags nDrawFlags = DrawTextFlags::MultiLine|DrawTextFlags::WordBreak|
384 DrawTextFlags::Left|DrawTextFlags::Top;
385 if (mnStyle & QuickHelpFlags::CtrlText)
386 nDrawFlags |= DrawTextFlags::Mnemonic;
387 rRenderContext.DrawText(maTextRect, maHelpText, nDrawFlags);
390 // border
391 if (!bNativeOK)
393 Size aSz = GetOutputSizePixel();
394 rRenderContext.DrawRect(Rectangle(Point(), aSz));
395 if (mnHelpWinStyle == HELPWINSTYLE_BALLOON)
397 aSz.Width() -= 2;
398 aSz.Height() -= 2;
399 Color aColor(rRenderContext.GetLineColor());
400 rRenderContext.SetLineColor(COL_GRAY);
401 rRenderContext.DrawRect(Rectangle(Point(1, 1), aSz));
402 rRenderContext.SetLineColor(aColor);
407 void HelpTextWindow::ShowHelp( sal_uInt16 nDelayMode )
409 sal_uLong nTimeout = 0;
410 if ( nDelayMode != HELPDELAY_NONE )
412 // In case of ExtendedHelp display help sooner
413 if ( ImplGetSVData()->maHelpData.mbExtHelpMode )
414 nTimeout = 15;
415 else
417 const HelpSettings& rHelpSettings = GetSettings().GetHelpSettings();
418 if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
419 nTimeout = rHelpSettings.GetTipDelay();
420 else
421 nTimeout = rHelpSettings.GetBalloonDelay();
424 if ( nDelayMode == HELPDELAY_SHORT )
425 nTimeout /= 3;
428 maShowTimer.SetTimeout( nTimeout );
429 maShowTimer.Start();
432 IMPL_LINK_TYPED( HelpTextWindow, TimerHdl, Timer*, pTimer, void)
434 if ( pTimer == &maShowTimer )
436 if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
438 // start auto-hide-timer for non-ShowTip windows
439 ImplSVData* pSVData = ImplGetSVData();
440 if ( this == pSVData->maHelpData.mpHelpWin )
441 maHideTimer.Start();
443 ImplShow();
445 else
447 DBG_ASSERT( pTimer == &maHideTimer, "HelpTextWindow::TimerHdl with bad Timer" );
448 ImplDestroyHelpWindow( true );
452 Size HelpTextWindow::CalcOutSize() const
454 Size aSz = maTextRect.GetSize();
455 aSz.Width() += 2*maTextRect.Left();
456 aSz.Height() += 2*maTextRect.Top();
457 return aSz;
460 void HelpTextWindow::RequestHelp( const HelpEvent& /*rHEvt*/ )
462 // Just to assure that Window::RequestHelp() is not called by
463 // ShowQuickHelp/ShowBalloonHelp in the HelpTextWindow.
466 OUString HelpTextWindow::GetText() const
468 return maHelpText;
471 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > HelpTextWindow::CreateAccessible()
473 return FloatingWindow::CreateAccessible();
476 void ImplShowHelpWindow( vcl::Window* pParent, sal_uInt16 nHelpWinStyle, QuickHelpFlags nStyle,
477 const OUString& rHelpText, const OUString& rStatusText,
478 const Point& rScreenPos, const Rectangle* pHelpArea )
480 ImplSVData* pSVData = ImplGetSVData();
482 if (rHelpText.isEmpty() && !pSVData->maHelpData.mbRequestingHelp)
483 return;
485 HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin;
486 sal_uInt16 nDelayMode = HELPDELAY_NORMAL;
487 if ( pHelpWin )
489 DBG_ASSERT( pHelpWin != pParent, "HelpInHelp ?!" );
491 if ( ( ( pHelpWin->GetHelpText() != rHelpText )
492 || ( pHelpWin->GetWinStyle() != nHelpWinStyle )
493 || ( pHelpArea
494 && ( pHelpWin->GetHelpArea() != *pHelpArea )
497 && pSVData->maHelpData.mbRequestingHelp
500 // remove help window if no HelpText or other HelpText or
501 // other help mode. but keep it if we are scrolling, ie not requesting help
502 bool bWasVisible = pHelpWin->IsVisible();
503 if ( bWasVisible )
504 nDelayMode = HELPDELAY_NONE; // display it quickly if we were already in quick help mode
505 pHelpWin = NULL;
506 ImplDestroyHelpWindow( bWasVisible );
508 else
510 bool const bTextChanged = rHelpText != pHelpWin->GetHelpText();
511 if ( bTextChanged || ( nStyle & QuickHelpFlags::ForceReposition ) )
513 vcl::Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
514 Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
515 if( pHelpWin->IsVisible() )
516 pWindow->Invalidate( aInvRect );
518 pHelpWin->SetHelpText( rHelpText );
519 // approach mouse position
520 ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
521 if( pHelpWin->IsVisible() )
522 pHelpWin->Invalidate();
527 if (!pHelpWin && !rHelpText.isEmpty())
529 sal_uInt64 nCurTime = tools::Time::GetSystemTicks();
530 if ( ( ( nCurTime - pSVData->maHelpData.mnLastHelpHideTime ) < pParent->GetSettings().GetHelpSettings().GetTipDelay() )
531 || ( nStyle & QuickHelpFlags::NoDelay )
533 nDelayMode = HELPDELAY_NONE;
535 DBG_ASSERT( !pHelpWin, "Noch ein HelpWin ?!" );
536 pHelpWin = VclPtr<HelpTextWindow>::Create( pParent, rHelpText, nHelpWinStyle, nStyle );
537 pSVData->maHelpData.mpHelpWin = pHelpWin;
538 pHelpWin->SetStatusText( rStatusText );
539 if ( pHelpArea )
540 pHelpWin->SetHelpArea( *pHelpArea );
542 // positioning
543 Size aSz = pHelpWin->CalcOutSize();
544 pHelpWin->SetOutputSizePixel( aSz );
545 ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
546 // if not called from Window::RequestHelp, then without delay...
547 if ( !pSVData->maHelpData.mbRequestingHelp )
548 nDelayMode = HELPDELAY_NONE;
549 pHelpWin->ShowHelp( nDelayMode );
553 void ImplDestroyHelpWindow( bool bUpdateHideTime )
555 ImplSVData* pSVData = ImplGetSVData();
556 VclPtr<HelpTextWindow> pHelpWin = pSVData->maHelpData.mpHelpWin;
557 if ( pHelpWin )
559 vcl::Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
560 // find out screen area covered by system help window
561 Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
562 if( pHelpWin->IsVisible() )
563 pWindow->Invalidate( aInvRect );
564 pSVData->maHelpData.mpHelpWin = NULL;
565 pSVData->maHelpData.mbKeyboardHelp = false;
566 pHelpWin->Hide();
567 pHelpWin.disposeAndClear();
568 if( bUpdateHideTime )
569 pSVData->maHelpData.mnLastHelpHideTime = tools::Time::GetSystemTicks();
573 void ImplSetHelpWindowPos( vcl::Window* pHelpWin, sal_uInt16 nHelpWinStyle, QuickHelpFlags nStyle,
574 const Point& rPos, const Rectangle* pHelpArea )
576 Point aPos = rPos;
577 Size aSz = pHelpWin->GetSizePixel();
578 Rectangle aScreenRect = pHelpWin->ImplGetFrameWindow()->GetDesktopRectPixel();
579 aPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( aPos );
580 // get mouse screen coords
581 Point mPos( pHelpWin->GetParent()->ImplGetFrameWindow()->GetPointerPosPixel() );
582 mPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( mPos );
584 if ( nHelpWinStyle == HELPWINSTYLE_QUICK )
586 if ( !(nStyle & QuickHelpFlags::NoAutoPos) )
588 long nScreenHeight = aScreenRect.GetHeight();
589 aPos.X() -= 4;
590 if ( aPos.Y() > aScreenRect.Top()+nScreenHeight-(nScreenHeight/4) )
591 aPos.Y() -= aSz.Height()+4;
592 else
593 aPos.Y() += 21;
596 else
598 // If it's the mouse position, move the window slightly
599 // so the mouse pointer does not cover it
600 if ( aPos == mPos )
602 aPos.X() += 12;
603 aPos.Y() += 16;
607 if ( nStyle & QuickHelpFlags::NoAutoPos )
609 if ( pHelpArea )
611 // convert help area to screen coords
612 Rectangle devHelpArea(
613 pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->TopLeft() ),
614 pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->BottomRight() ) );
616 // Welche Position vom Rechteck?
617 aPos = devHelpArea.Center();
619 if ( nStyle & QuickHelpFlags::Left )
620 aPos.X() = devHelpArea.Left();
621 else if ( nStyle & QuickHelpFlags::Right )
622 aPos.X() = devHelpArea.Right();
624 if ( nStyle & QuickHelpFlags::Top )
625 aPos.Y() = devHelpArea.Top();
626 else if ( nStyle & QuickHelpFlags::Bottom )
627 aPos.Y() = devHelpArea.Bottom();
630 // which direction?
631 if ( nStyle & QuickHelpFlags::Left )
633 else if ( nStyle & QuickHelpFlags::Right )
634 aPos.X() -= aSz.Width();
635 else
636 aPos.X() -= aSz.Width()/2;
638 if ( nStyle & QuickHelpFlags::Top )
640 else if ( nStyle & QuickHelpFlags::Bottom )
641 aPos.Y() -= aSz.Height();
642 else
643 aPos.Y() -= aSz.Height()/2;
646 if ( aPos.X() < aScreenRect.Left() )
647 aPos.X() = aScreenRect.Left();
648 else if ( ( aPos.X() + aSz.Width() ) > aScreenRect.Right() )
649 aPos.X() = aScreenRect.Right() - aSz.Width();
650 if ( aPos.Y() < aScreenRect.Top() )
651 aPos.Y() = aScreenRect.Top();
652 else if ( ( aPos.Y() + aSz.Height() ) > aScreenRect.Bottom() )
653 aPos.Y() = aScreenRect.Bottom() - aSz.Height();
655 if( ! (nStyle & QuickHelpFlags::NoEvadePointer) )
657 /* the remark below should be obsolete by now as the helpwindow should
658 not be focusable, leaving it as a hint. However it is sensible in most
659 conditions to evade the mouse pointer so the content window is fully visible.
661 // the popup must not appear under the mouse
662 // otherwise it would directly be closed due to a focus change...
664 Rectangle aHelpRect( aPos, aSz );
665 if( aHelpRect.IsInside( mPos ) )
667 Point delta(2,2);
668 Point pSize( aSz.Width(), aSz.Height() );
669 Point pTest( mPos - pSize - delta );
670 if( pTest.X() > aScreenRect.Left() && pTest.Y() > aScreenRect.Top() )
671 aPos = pTest;
672 else
673 aPos = mPos + delta;
677 vcl::Window* pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
678 aPos = pWindow->AbsoluteScreenToOutputPixel( aPos );
679 pHelpWin->SetPosPixel( aPos );
682 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */