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 <comphelper/string.hxx>
21 :
22 : #include "tools/debug.hxx"
23 : #include "tools/diagnose_ex.h"
24 : #include "tools/time.hxx"
25 :
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 :
32 : #include "helpwin.hxx"
33 : #include "svdata.hxx"
34 :
35 : // =======================================================================
36 :
37 : #define HELPWINSTYLE_QUICK 0
38 : #define HELPWINSTYLE_BALLOON 1
39 :
40 : #define HELPTEXTMARGIN_QUICK 3
41 : #define HELPTEXTMARGIN_BALLOON 6
42 :
43 : #define HELPDELAY_NORMAL 1
44 : #define HELPDELAY_SHORT 2
45 : #define HELPDELAY_NONE 3
46 :
47 : #define HELPTEXTMAXLEN 150
48 :
49 : // =======================================================================
50 :
51 133 : Help::Help()
52 : {
53 133 : }
54 :
55 83 : Help::~Help()
56 : {
57 83 : }
58 :
59 : // -----------------------------------------------------------------------
60 :
61 : // -----------------------------------------------------------------------
62 :
63 0 : sal_Bool Help::Start( const OUString&, const Window* )
64 : {
65 0 : return sal_False;
66 : }
67 :
68 0 : sal_Bool Help::SearchKeyword( const OUString& )
69 : {
70 0 : return sal_False;
71 : }
72 :
73 : // -----------------------------------------------------------------------
74 :
75 0 : OUString Help::GetHelpText( const OUString&, const Window* )
76 : {
77 0 : return ImplGetSVEmptyStr();
78 : }
79 :
80 : // -----------------------------------------------------------------------
81 :
82 133 : void Help::EnableContextHelp()
83 : {
84 133 : ImplGetSVData()->maHelpData.mbContextHelp = sal_True;
85 133 : }
86 :
87 : // -----------------------------------------------------------------------
88 :
89 0 : void Help::DisableContextHelp()
90 : {
91 0 : ImplGetSVData()->maHelpData.mbContextHelp = sal_False;
92 0 : }
93 :
94 : // -----------------------------------------------------------------------
95 :
96 0 : sal_Bool Help::IsContextHelpEnabled()
97 : {
98 0 : return ImplGetSVData()->maHelpData.mbContextHelp;
99 : }
100 :
101 : // -----------------------------------------------------------------------
102 :
103 133 : void Help::EnableExtHelp()
104 : {
105 133 : ImplGetSVData()->maHelpData.mbExtHelp = sal_True;
106 133 : }
107 :
108 : // -----------------------------------------------------------------------
109 :
110 0 : void Help::DisableExtHelp()
111 : {
112 0 : ImplGetSVData()->maHelpData.mbExtHelp = sal_False;
113 0 : }
114 :
115 : // -----------------------------------------------------------------------
116 :
117 0 : sal_Bool Help::IsExtHelpEnabled()
118 : {
119 0 : return ImplGetSVData()->maHelpData.mbExtHelp;
120 : }
121 :
122 : // -----------------------------------------------------------------------
123 :
124 0 : sal_Bool Help::StartExtHelp()
125 : {
126 0 : ImplSVData* pSVData = ImplGetSVData();
127 :
128 0 : if ( pSVData->maHelpData.mbExtHelp && !pSVData->maHelpData.mbExtHelpMode )
129 : {
130 0 : pSVData->maHelpData.mbExtHelpMode = sal_True;
131 0 : pSVData->maHelpData.mbOldBalloonMode = pSVData->maHelpData.mbBalloonHelp;
132 0 : pSVData->maHelpData.mbBalloonHelp = sal_True;
133 0 : if ( pSVData->maWinData.mpAppWin )
134 0 : pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
135 0 : return sal_True;
136 : }
137 :
138 0 : return sal_False;
139 : }
140 :
141 : // -----------------------------------------------------------------------
142 :
143 0 : sal_Bool Help::EndExtHelp()
144 : {
145 0 : ImplSVData* pSVData = ImplGetSVData();
146 :
147 0 : if ( pSVData->maHelpData.mbExtHelp && pSVData->maHelpData.mbExtHelpMode )
148 : {
149 0 : pSVData->maHelpData.mbExtHelpMode = sal_False;
150 0 : pSVData->maHelpData.mbBalloonHelp = pSVData->maHelpData.mbOldBalloonMode;
151 0 : if ( pSVData->maWinData.mpAppWin )
152 0 : pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
153 0 : return sal_True;
154 : }
155 :
156 0 : return sal_False;
157 : }
158 :
159 : // -----------------------------------------------------------------------
160 :
161 0 : void Help::EnableBalloonHelp()
162 : {
163 0 : ImplGetSVData()->maHelpData.mbBalloonHelp = sal_True;
164 0 : }
165 :
166 : // -----------------------------------------------------------------------
167 :
168 133 : void Help::DisableBalloonHelp()
169 : {
170 133 : ImplGetSVData()->maHelpData.mbBalloonHelp = sal_False;
171 133 : }
172 :
173 : // -----------------------------------------------------------------------
174 :
175 133 : sal_Bool Help::IsBalloonHelpEnabled()
176 : {
177 133 : return ImplGetSVData()->maHelpData.mbBalloonHelp;
178 : }
179 :
180 : // -----------------------------------------------------------------------
181 :
182 0 : sal_Bool Help::ShowBalloon( Window* pParent,
183 : const Point& rScreenPos,
184 : const OUString& rHelpText )
185 : {
186 : ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, 0,
187 0 : rHelpText, ImplGetSVEmptyStr(), rScreenPos );
188 :
189 0 : return sal_True;
190 : }
191 :
192 : // -----------------------------------------------------------------------
193 :
194 0 : sal_Bool Help::ShowBalloon( Window* pParent,
195 : const Point& rScreenPos, const Rectangle& rRect,
196 : const OUString& rHelpText )
197 : {
198 : ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, 0,
199 0 : rHelpText, ImplGetSVEmptyStr(), rScreenPos, &rRect );
200 :
201 0 : return sal_True;
202 : }
203 :
204 : // -----------------------------------------------------------------------
205 :
206 266 : void Help::EnableQuickHelp()
207 : {
208 266 : ImplGetSVData()->maHelpData.mbQuickHelp = sal_True;
209 266 : }
210 :
211 : // -----------------------------------------------------------------------
212 :
213 0 : void Help::DisableQuickHelp()
214 : {
215 0 : ImplGetSVData()->maHelpData.mbQuickHelp = sal_False;
216 0 : }
217 :
218 : // -----------------------------------------------------------------------
219 :
220 133 : sal_Bool Help::IsQuickHelpEnabled()
221 : {
222 133 : return ImplGetSVData()->maHelpData.mbQuickHelp;
223 : }
224 :
225 : // -----------------------------------------------------------------------
226 :
227 0 : sal_Bool Help::ShowQuickHelp( Window* pParent,
228 : const Rectangle& rScreenRect,
229 : const OUString& rHelpText,
230 : const OUString& rLongHelpText,
231 : sal_uInt16 nStyle )
232 : {
233 : ImplShowHelpWindow( pParent, HELPWINSTYLE_QUICK, nStyle,
234 : rHelpText, rLongHelpText,
235 0 : pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
236 0 : return sal_True;
237 : }
238 :
239 : // -----------------------------------------------------------------------
240 :
241 0 : void Help::HideBalloonAndQuickHelp()
242 : {
243 0 : HelpTextWindow const * pHelpWin = ImplGetSVData()->maHelpData.mpHelpWin;
244 0 : bool const bIsVisible = ( pHelpWin != NULL ) && pHelpWin->IsVisible();
245 0 : ImplDestroyHelpWindow( bIsVisible );
246 0 : }
247 :
248 : // -----------------------------------------------------------------------
249 :
250 0 : sal_uIntPtr Help::ShowTip( Window* pParent, const Rectangle& rScreenRect,
251 : const OUString& rText, sal_uInt16 nStyle )
252 : {
253 0 : sal_uInt16 nHelpWinStyle = ( ( nStyle & QUICKHELP_TIP_STYLE_BALLOON ) != 0 ) ? HELPWINSTYLE_BALLOON : HELPWINSTYLE_QUICK;
254 0 : HelpTextWindow* pHelpWin = new HelpTextWindow( pParent, rText, nHelpWinStyle, nStyle );
255 :
256 0 : sal_uIntPtr nId = reinterpret_cast< sal_uIntPtr >( pHelpWin );
257 0 : UpdateTip( nId, pParent, rScreenRect, rText );
258 :
259 0 : pHelpWin->ShowHelp( HELPDELAY_NONE );
260 0 : return nId;
261 : }
262 :
263 : // -----------------------------------------------------------------------
264 :
265 0 : void Help::UpdateTip( sal_uIntPtr nId, Window* pParent, const Rectangle& rScreenRect, const OUString& rText )
266 : {
267 0 : HelpTextWindow* pHelpWin = reinterpret_cast< HelpTextWindow* >( nId );
268 0 : ENSURE_OR_RETURN_VOID( pHelpWin != NULL, "Help::UpdateTip: invalid ID!" );
269 :
270 0 : Size aSz = pHelpWin->CalcOutSize();
271 0 : pHelpWin->SetOutputSizePixel( aSz );
272 0 : ImplSetHelpWindowPos( pHelpWin, pHelpWin->GetWinStyle(), pHelpWin->GetStyle(),
273 0 : pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
274 :
275 0 : pHelpWin->SetHelpText( rText );
276 0 : pHelpWin->Invalidate();
277 : }
278 :
279 : // -----------------------------------------------------------------------
280 :
281 0 : void Help::HideTip( sal_uLong nId )
282 : {
283 0 : HelpTextWindow* pHelpWin = (HelpTextWindow*)nId;
284 0 : Window* pFrameWindow = pHelpWin->ImplGetFrameWindow();
285 0 : pHelpWin->Hide();
286 : // trigger update, so that a Paint is instantly triggered since we do not save the background
287 0 : pFrameWindow->ImplUpdateAll();
288 0 : delete pHelpWin;
289 0 : ImplGetSVData()->maHelpData.mnLastHelpHideTime = Time::GetSystemTicks();
290 0 : }
291 :
292 : // =======================================================================
293 :
294 0 : HelpTextWindow::HelpTextWindow( Window* pParent, const OUString& rText, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle ) :
295 : FloatingWindow( pParent, WB_SYSTEMWINDOW|WB_TOOLTIPWIN ), // #105827# if we change the parent, mirroring will not work correctly when positioning this window
296 0 : maHelpText( rText )
297 : {
298 0 : SetType( WINDOW_HELPTEXTWINDOW );
299 0 : ImplSetMouseTransparent( sal_True );
300 0 : mnHelpWinStyle = nHelpWinStyle;
301 0 : mnStyle = nStyle;
302 : // on windows this will raise the application window, because help windows are system windows now
303 : // EnableAlwaysOnTop();
304 0 : EnableSaveBackground();
305 :
306 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
307 0 : SetPointFont( rStyleSettings.GetHelpFont() );
308 0 : SetTextColor( rStyleSettings.GetHelpTextColor() );
309 0 : SetTextAlign( ALIGN_TOP );
310 0 : if ( IsNativeControlSupported( CTRL_TOOLTIP, PART_ENTIRE_CONTROL ) )
311 : {
312 0 : EnableChildTransparentMode( sal_True );
313 0 : SetParentClipMode( PARENTCLIPMODE_NOCLIP );
314 0 : SetPaintTransparent( sal_True );
315 0 : SetBackground();
316 : }
317 : else
318 0 : SetBackground( Wallpaper( rStyleSettings.GetHelpColor() ) );
319 0 : if( rStyleSettings.GetHelpColor().IsDark() )
320 0 : SetLineColor( COL_WHITE );
321 : else
322 0 : SetLineColor( COL_BLACK );
323 0 : SetFillColor();
324 :
325 0 : if( mnStyle & QUICKHELP_BIDI_RTL )
326 : {
327 0 : sal_uLong nLayoutMode = GetLayoutMode();
328 0 : nLayoutMode |= TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT;
329 0 : SetLayoutMode( nLayoutMode );
330 : }
331 0 : SetHelpText( rText );
332 0 : Window::SetHelpText( rText );
333 :
334 0 : ImplSVData* pSVData = ImplGetSVData();
335 0 : if ( pSVData->maHelpData.mbSetKeyboardHelp )
336 0 : pSVData->maHelpData.mbKeyboardHelp = sal_True;
337 :
338 0 : const HelpSettings& rHelpSettings = pParent->GetSettings().GetHelpSettings();
339 0 : maShowTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
340 0 : maHideTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
341 0 : maHideTimer.SetTimeout( rHelpSettings.GetTipTimeout() );
342 0 : }
343 :
344 : // -----------------------------------------------------------------------
345 :
346 0 : HelpTextWindow::~HelpTextWindow()
347 : {
348 0 : maShowTimer.Stop();
349 0 : maHideTimer.Stop();
350 :
351 0 : if( this == ImplGetSVData()->maHelpData.mpHelpWin )
352 0 : ImplGetSVData()->maHelpData.mpHelpWin = NULL;
353 0 : }
354 :
355 : // -----------------------------------------------------------------------
356 :
357 0 : void HelpTextWindow::SetHelpText( const OUString& rHelpText )
358 : {
359 0 : maHelpText = rHelpText;
360 0 : if ( mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.getLength() < HELPTEXTMAXLEN)
361 : {
362 0 : Size aSize;
363 0 : aSize.Height() = GetTextHeight();
364 0 : if ( mnStyle & QUICKHELP_CTRLTEXT )
365 0 : aSize.Width() = GetCtrlTextWidth( maHelpText );
366 : else
367 0 : aSize.Width() = GetTextWidth( maHelpText );
368 0 : maTextRect = Rectangle( Point( HELPTEXTMARGIN_QUICK, HELPTEXTMARGIN_QUICK ), aSize );
369 : }
370 : else // HELPWINSTYLE_BALLOON
371 : {
372 0 : Point aTmpPoint;
373 0 : sal_Int32 nCharsInLine = 35 + ((maHelpText.getLength()/100)*5);
374 : // average width to have all windows consistent
375 0 : OUStringBuffer aBuf;
376 0 : comphelper::string::padToLength(aBuf, nCharsInLine, 'x');
377 0 : OUString aXXX = aBuf.makeStringAndClear();
378 0 : long nWidth = GetTextWidth( aXXX );
379 0 : Size aTmpSize( nWidth, 0x7FFFFFFF );
380 0 : Rectangle aTry1( aTmpPoint, aTmpSize );
381 : sal_uInt16 nDrawFlags = TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK |
382 0 : TEXT_DRAW_LEFT | TEXT_DRAW_TOP;
383 0 : if ( mnStyle & QUICKHELP_CTRLTEXT )
384 0 : nDrawFlags |= TEXT_DRAW_MNEMONIC;
385 0 : Rectangle aTextRect = GetTextRect( aTry1, maHelpText, nDrawFlags );
386 :
387 : // get a better width later...
388 0 : maTextRect = aTextRect;
389 :
390 : // safety distance...
391 0 : maTextRect.SetPos( Point( HELPTEXTMARGIN_BALLOON, HELPTEXTMARGIN_BALLOON ) );
392 : }
393 :
394 0 : Size aSize( CalcOutSize() );
395 0 : SetOutputSizePixel( aSize );
396 0 : }
397 :
398 : // -----------------------------------------------------------------------
399 :
400 0 : void HelpTextWindow::ImplShow()
401 : {
402 0 : ImplDelData aDogTag( this );
403 0 : Show( sal_True, SHOW_NOACTIVATE );
404 0 : if( !aDogTag.IsDead() )
405 0 : Update();
406 0 : }
407 :
408 : // -----------------------------------------------------------------------
409 :
410 0 : void HelpTextWindow::Paint( const Rectangle& )
411 : {
412 : // paint native background
413 0 : bool bNativeOK = false;
414 0 : if ( IsNativeControlSupported( CTRL_TOOLTIP, PART_ENTIRE_CONTROL ) )
415 : {
416 : // #i46472# workaround gcc3.3 temporary problem
417 0 : Rectangle aCtrlRegion( Point( 0, 0 ), GetOutputSizePixel() );
418 0 : ImplControlValue aControlValue;
419 : bNativeOK = DrawNativeControl( CTRL_TOOLTIP, PART_ENTIRE_CONTROL, aCtrlRegion,
420 0 : 0, aControlValue, OUString() );
421 : }
422 :
423 : // paint text
424 0 : if ( mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.getLength() < HELPTEXTMAXLEN)
425 : {
426 0 : if ( mnStyle & QUICKHELP_CTRLTEXT )
427 0 : DrawCtrlText( maTextRect.TopLeft(), maHelpText );
428 : else
429 0 : DrawText( maTextRect.TopLeft(), maHelpText );
430 : }
431 : else // HELPWINSTYLE_BALLOON
432 : {
433 : sal_uInt16 nDrawFlags = TEXT_DRAW_MULTILINE|TEXT_DRAW_WORDBREAK|
434 0 : TEXT_DRAW_LEFT|TEXT_DRAW_TOP;
435 0 : if ( mnStyle & QUICKHELP_CTRLTEXT )
436 0 : nDrawFlags |= TEXT_DRAW_MNEMONIC;
437 0 : DrawText( maTextRect, maHelpText, nDrawFlags );
438 : }
439 :
440 : // border
441 0 : if( ! bNativeOK )
442 : {
443 0 : Size aSz = GetOutputSizePixel();
444 0 : DrawRect( Rectangle( Point(), aSz ) );
445 0 : if ( mnHelpWinStyle == HELPWINSTYLE_BALLOON )
446 : {
447 0 : aSz.Width() -= 2;
448 0 : aSz.Height() -= 2;
449 0 : Color aColor( GetLineColor() );
450 0 : SetLineColor( ( COL_GRAY ) );
451 0 : DrawRect( Rectangle( Point( 1, 1 ), aSz ) );
452 0 : SetLineColor( aColor );
453 : }
454 : }
455 0 : }
456 :
457 : // -----------------------------------------------------------------------
458 :
459 0 : void HelpTextWindow::ShowHelp( sal_uInt16 nDelayMode )
460 : {
461 0 : sal_uLong nTimeout = 0;
462 0 : if ( nDelayMode != HELPDELAY_NONE )
463 : {
464 : // In case of ExtendedHelp display help sooner
465 0 : if ( ImplGetSVData()->maHelpData.mbExtHelpMode )
466 0 : nTimeout = 15;
467 : else
468 : {
469 0 : const HelpSettings& rHelpSettings = GetSettings().GetHelpSettings();
470 0 : if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
471 0 : nTimeout = rHelpSettings.GetTipDelay();
472 : else
473 0 : nTimeout = rHelpSettings.GetBalloonDelay();
474 : }
475 :
476 0 : if ( nDelayMode == HELPDELAY_SHORT )
477 0 : nTimeout /= 3;
478 : }
479 :
480 0 : maShowTimer.SetTimeout( nTimeout );
481 0 : maShowTimer.Start();
482 0 : }
483 :
484 : // -----------------------------------------------------------------------
485 :
486 0 : IMPL_LINK( HelpTextWindow, TimerHdl, Timer*, pTimer)
487 : {
488 0 : if ( pTimer == &maShowTimer )
489 : {
490 0 : if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
491 : {
492 : // start auto-hide-timer for non-ShowTip windows
493 0 : ImplSVData* pSVData = ImplGetSVData();
494 0 : if ( this == pSVData->maHelpData.mpHelpWin )
495 0 : maHideTimer.Start();
496 : }
497 0 : ImplShow();
498 : }
499 : else
500 : {
501 : DBG_ASSERT( pTimer == &maHideTimer, "HelpTextWindow::TimerHdl with bad Timer" );
502 0 : ImplDestroyHelpWindow( true );
503 : }
504 :
505 0 : return 1;
506 : }
507 :
508 : // -----------------------------------------------------------------------
509 :
510 0 : Size HelpTextWindow::CalcOutSize() const
511 : {
512 0 : Size aSz = maTextRect.GetSize();
513 0 : aSz.Width() += 2*maTextRect.Left();
514 0 : aSz.Height() += 2*maTextRect.Top();
515 0 : return aSz;
516 : }
517 :
518 : // -----------------------------------------------------------------------
519 :
520 0 : void HelpTextWindow::RequestHelp( const HelpEvent& /*rHEvt*/ )
521 : {
522 : // Just to assure that Window::RequestHelp() is not called by
523 : // ShowQuickHelp/ShowBalloonHelp in the HelpTextWindow.
524 0 : }
525 :
526 : // -----------------------------------------------------------------------
527 :
528 0 : OUString HelpTextWindow::GetText() const
529 : {
530 0 : return maHelpText;
531 : }
532 :
533 : // -----------------------------------------------------------------------
534 :
535 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > HelpTextWindow::CreateAccessible()
536 : {
537 0 : return FloatingWindow::CreateAccessible();
538 : }
539 :
540 :
541 : // =======================================================================
542 :
543 0 : void ImplShowHelpWindow( Window* pParent, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle,
544 : const OUString& rHelpText, const OUString& rStatusText,
545 : const Point& rScreenPos, const Rectangle* pHelpArea )
546 : {
547 0 : ImplSVData* pSVData = ImplGetSVData();
548 :
549 0 : if (rHelpText.isEmpty() && !pSVData->maHelpData.mbRequestingHelp)
550 0 : return;
551 :
552 0 : HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin;
553 0 : sal_uInt16 nDelayMode = HELPDELAY_NORMAL;
554 0 : if ( pHelpWin )
555 : {
556 : DBG_ASSERT( pHelpWin != pParent, "HelpInHelp ?!" );
557 :
558 0 : if ( ( ( pHelpWin->GetHelpText() != rHelpText )
559 0 : || ( pHelpWin->GetWinStyle() != nHelpWinStyle )
560 0 : || ( pHelpArea
561 0 : && ( pHelpWin->GetHelpArea() != *pHelpArea )
562 : )
563 : )
564 0 : && pSVData->maHelpData.mbRequestingHelp
565 : )
566 : {
567 : // remove help window if no HelpText or other HelpText or
568 : // other help mode. but keep it if we are scrolling, ie not requesting help
569 0 : bool bWasVisible = pHelpWin->IsVisible();
570 0 : if ( bWasVisible )
571 0 : nDelayMode = HELPDELAY_NONE; // display it quickly if we were already in quick help mode
572 0 : pHelpWin = NULL;
573 0 : ImplDestroyHelpWindow( bWasVisible );
574 : }
575 : else
576 : {
577 0 : bool const bTextChanged = rHelpText != pHelpWin->GetHelpText();
578 0 : if ( bTextChanged || ( ( nStyle & QUICKHELP_FORCE_REPOSITION ) != 0 ) )
579 : {
580 0 : Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
581 0 : Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
582 0 : if( pHelpWin->IsVisible() )
583 0 : pWindow->Invalidate( aInvRect );
584 :
585 0 : pHelpWin->SetHelpText( rHelpText );
586 : // approach mouse position
587 0 : ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
588 0 : if( pHelpWin->IsVisible() )
589 0 : pHelpWin->Invalidate();
590 : }
591 : }
592 : }
593 :
594 0 : if (!pHelpWin && !rHelpText.isEmpty())
595 : {
596 0 : sal_uLong nCurTime = Time::GetSystemTicks();
597 0 : if ( ( ( nCurTime - pSVData->maHelpData.mnLastHelpHideTime ) < pParent->GetSettings().GetHelpSettings().GetTipDelay() )
598 0 : || ( ( nStyle & QUICKHELP_NO_DELAY ) != 0 )
599 : )
600 0 : nDelayMode = HELPDELAY_NONE;
601 :
602 : DBG_ASSERT( !pHelpWin, "Noch ein HelpWin ?!" );
603 0 : pHelpWin = new HelpTextWindow( pParent, rHelpText, nHelpWinStyle, nStyle );
604 0 : pSVData->maHelpData.mpHelpWin = pHelpWin;
605 0 : pHelpWin->SetStatusText( rStatusText );
606 0 : if ( pHelpArea )
607 0 : pHelpWin->SetHelpArea( *pHelpArea );
608 :
609 : // positioning
610 0 : Size aSz = pHelpWin->CalcOutSize();
611 0 : pHelpWin->SetOutputSizePixel( aSz );
612 0 : ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
613 : // if not called from Window::RequestHelp, then without delay...
614 0 : if ( !pSVData->maHelpData.mbRequestingHelp )
615 0 : nDelayMode = HELPDELAY_NONE;
616 0 : pHelpWin->ShowHelp( nDelayMode );
617 : }
618 : }
619 :
620 : // -----------------------------------------------------------------------
621 :
622 2248 : void ImplDestroyHelpWindow( bool bUpdateHideTime )
623 : {
624 2248 : ImplSVData* pSVData = ImplGetSVData();
625 2248 : HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin;
626 2248 : if ( pHelpWin )
627 : {
628 0 : Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
629 : // find out screen area covered by system help window
630 0 : Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
631 0 : if( pHelpWin->IsVisible() )
632 0 : pWindow->Invalidate( aInvRect );
633 0 : pSVData->maHelpData.mpHelpWin = NULL;
634 0 : pSVData->maHelpData.mbKeyboardHelp = sal_False;
635 0 : pHelpWin->Hide();
636 0 : delete pHelpWin;
637 0 : if( bUpdateHideTime )
638 0 : pSVData->maHelpData.mnLastHelpHideTime = Time::GetSystemTicks();
639 : }
640 2248 : }
641 :
642 : // -----------------------------------------------------------------------
643 :
644 0 : void ImplSetHelpWindowPos( Window* pHelpWin, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle,
645 : const Point& rPos, const Rectangle* pHelpArea )
646 : {
647 0 : Point aPos = rPos;
648 0 : Size aSz = pHelpWin->GetSizePixel();
649 0 : Rectangle aScreenRect = pHelpWin->ImplGetFrameWindow()->GetDesktopRectPixel();
650 0 : aPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( aPos );
651 : // get mouse screen coords
652 0 : Point mPos( pHelpWin->GetParent()->ImplGetFrameWindow()->GetPointerPosPixel() );
653 0 : mPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( mPos );
654 :
655 0 : if ( nHelpWinStyle == HELPWINSTYLE_QUICK )
656 : {
657 0 : if ( !(nStyle & QUICKHELP_NOAUTOPOS) )
658 : {
659 0 : long nScreenHeight = aScreenRect.GetHeight();
660 0 : aPos.X() -= 4;
661 0 : if ( aPos.Y() > aScreenRect.Top()+nScreenHeight-(nScreenHeight/4) )
662 0 : aPos.Y() -= aSz.Height()+4;
663 : else
664 0 : aPos.Y() += 21;
665 : }
666 : }
667 : else
668 : {
669 : // If it's the mouse position, move the window slightly
670 : // so the mouse pointer does not cover it
671 0 : if ( aPos == mPos )
672 : {
673 0 : aPos.X() += 12;
674 0 : aPos.Y() += 16;
675 : }
676 : }
677 :
678 0 : if ( nStyle & QUICKHELP_NOAUTOPOS )
679 : {
680 0 : if ( pHelpArea )
681 : {
682 : // convert help area to screen coords
683 : Rectangle devHelpArea(
684 0 : pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->TopLeft() ),
685 0 : pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->BottomRight() ) );
686 :
687 : // Welche Position vom Rechteck?
688 0 : aPos = devHelpArea.Center();
689 :
690 0 : if ( nStyle & QUICKHELP_LEFT )
691 0 : aPos.X() = devHelpArea.Left();
692 0 : else if ( nStyle & QUICKHELP_RIGHT )
693 0 : aPos.X() = devHelpArea.Right();
694 :
695 0 : if ( nStyle & QUICKHELP_TOP )
696 0 : aPos.Y() = devHelpArea.Top();
697 0 : else if ( nStyle & QUICKHELP_BOTTOM )
698 0 : aPos.Y() = devHelpArea.Bottom();
699 : }
700 :
701 : // which direction?
702 0 : if ( nStyle & QUICKHELP_LEFT )
703 : ;
704 0 : else if ( nStyle & QUICKHELP_RIGHT )
705 0 : aPos.X() -= aSz.Width();
706 : else
707 0 : aPos.X() -= aSz.Width()/2;
708 :
709 0 : if ( nStyle & QUICKHELP_TOP )
710 : ;
711 0 : else if ( nStyle & QUICKHELP_BOTTOM )
712 0 : aPos.Y() -= aSz.Height();
713 : else
714 0 : aPos.Y() -= aSz.Height()/2;
715 : }
716 :
717 0 : if ( aPos.X() < aScreenRect.Left() )
718 0 : aPos.X() = aScreenRect.Left();
719 0 : else if ( ( aPos.X() + aSz.Width() ) > aScreenRect.Right() )
720 0 : aPos.X() = aScreenRect.Right() - aSz.Width();
721 0 : if ( aPos.Y() < aScreenRect.Top() )
722 0 : aPos.Y() = aScreenRect.Top();
723 0 : else if ( ( aPos.Y() + aSz.Height() ) > aScreenRect.Bottom() )
724 0 : aPos.Y() = aScreenRect.Bottom() - aSz.Height();
725 :
726 0 : if( ! (nStyle & QUICKHELP_NOEVADEPOINTER) )
727 : {
728 : /* the remark below should be obsolete by now as the helpwindow should
729 : not be focusable, leaving it as a hint. However it is sensible in most
730 : conditions to evade the mouse pointer so the content window is fully visible.
731 :
732 : // the popup must not appear under the mouse
733 : // otherwise it would directly be closed due to a focus change...
734 : */
735 0 : Rectangle aHelpRect( aPos, aSz );
736 0 : if( aHelpRect.IsInside( mPos ) )
737 : {
738 0 : Point delta(2,2);
739 0 : Point pSize( aSz.Width(), aSz.Height() );
740 0 : Point pTest( mPos - pSize - delta );
741 0 : if( pTest.X() > aScreenRect.Left() && pTest.Y() > aScreenRect.Top() )
742 0 : aPos = pTest;
743 : else
744 0 : aPos = mPos + delta;
745 : }
746 : }
747 :
748 0 : Window* pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
749 0 : aPos = pWindow->AbsoluteScreenToOutputPixel( aPos );
750 0 : pHelpWin->SetPosPixel( aPos );
751 465 : }
752 :
753 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|