xref: /AOO41X/main/vcl/source/app/help.cxx (revision 0406e650f5976ecb08a09d8623c16d4a678400cc)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_vcl.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include "tools/debug.hxx"
26cdf0e10cSrcweir #include "tools/diagnose_ex.h"
27cdf0e10cSrcweir #include "tools/time.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "vcl/window.hxx"
30cdf0e10cSrcweir #include "vcl/event.hxx"
31cdf0e10cSrcweir #include "vcl/svapp.hxx"
32cdf0e10cSrcweir #include "vcl/wrkwin.hxx"
33cdf0e10cSrcweir #include "vcl/help.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "helpwin.hxx"
36cdf0e10cSrcweir #include "svdata.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // =======================================================================
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #define HELPWINSTYLE_QUICK      0
41cdf0e10cSrcweir #define HELPWINSTYLE_BALLOON    1
42cdf0e10cSrcweir 
435793b69bSmseidel #define HELPTEXTMARGIN_QUICK    4
44*0406e650Smseidel #define HELPTEXTMARGIN_BALLOON  4 // same margin as quickhelp
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #define HELPDELAY_NORMAL        1
47cdf0e10cSrcweir #define HELPDELAY_SHORT         2
48cdf0e10cSrcweir #define HELPDELAY_NONE          3
49cdf0e10cSrcweir 
50cdf0e10cSrcweir // =======================================================================
51cdf0e10cSrcweir 
Help()52cdf0e10cSrcweir Help::Help()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
~Help()56cdf0e10cSrcweir Help::~Help()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // -----------------------------------------------------------------------
61cdf0e10cSrcweir 
OpenHelpAgent(const rtl::OString &)62cdf0e10cSrcweir void Help::OpenHelpAgent( const rtl::OString& )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // -----------------------------------------------------------------------
67cdf0e10cSrcweir 
Start(const XubString &,const Window *)68cdf0e10cSrcweir sal_Bool Help::Start( const XubString&, const Window* )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     return sal_False;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
SearchKeyword(const XubString &)73cdf0e10cSrcweir sal_Bool Help::SearchKeyword( const XubString& )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     return sal_False;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // -----------------------------------------------------------------------
79cdf0e10cSrcweir 
GetHelpText(const String &,const Window *)80cdf0e10cSrcweir XubString Help::GetHelpText( const String&, const Window* )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     return ImplGetSVEmptyStr();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // -----------------------------------------------------------------------
86cdf0e10cSrcweir 
EnableContextHelp()87cdf0e10cSrcweir void Help::EnableContextHelp()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbContextHelp = sal_True;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // -----------------------------------------------------------------------
93cdf0e10cSrcweir 
DisableContextHelp()94cdf0e10cSrcweir void Help::DisableContextHelp()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbContextHelp = sal_False;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir // -----------------------------------------------------------------------
100cdf0e10cSrcweir 
IsContextHelpEnabled()101cdf0e10cSrcweir sal_Bool Help::IsContextHelpEnabled()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     return ImplGetSVData()->maHelpData.mbContextHelp;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir // -----------------------------------------------------------------------
107cdf0e10cSrcweir 
StartContextHelp()108cdf0e10cSrcweir sal_Bool Help::StartContextHelp()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     if ( pSVData->maHelpData.mbContextHelp )
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         Window* pWindow = pSVData->maWinData.mpFocusWin;
115cdf0e10cSrcweir         if ( pWindow )
116cdf0e10cSrcweir         {
117cdf0e10cSrcweir             Point       aMousePos = pWindow->OutputToScreenPixel( pWindow->GetPointerPosPixel() );
118cdf0e10cSrcweir             HelpEvent   aHelpEvent( aMousePos, HELPMODE_CONTEXT );
119cdf0e10cSrcweir             pWindow->RequestHelp( aHelpEvent );
120cdf0e10cSrcweir             return sal_True;
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     return sal_False;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir // -----------------------------------------------------------------------
128cdf0e10cSrcweir 
EnableExtHelp()129cdf0e10cSrcweir void Help::EnableExtHelp()
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbExtHelp = sal_True;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // -----------------------------------------------------------------------
135cdf0e10cSrcweir 
DisableExtHelp()136cdf0e10cSrcweir void Help::DisableExtHelp()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbExtHelp = sal_False;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // -----------------------------------------------------------------------
142cdf0e10cSrcweir 
IsExtHelpEnabled()143cdf0e10cSrcweir sal_Bool Help::IsExtHelpEnabled()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     return ImplGetSVData()->maHelpData.mbExtHelp;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // -----------------------------------------------------------------------
149cdf0e10cSrcweir 
StartExtHelp()150cdf0e10cSrcweir sal_Bool Help::StartExtHelp()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     if ( pSVData->maHelpData.mbExtHelp && !pSVData->maHelpData.mbExtHelpMode )
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         pSVData->maHelpData.mbExtHelpMode = sal_True;
157cdf0e10cSrcweir         pSVData->maHelpData.mbOldBalloonMode = pSVData->maHelpData.mbBalloonHelp;
158cdf0e10cSrcweir         pSVData->maHelpData.mbBalloonHelp = sal_True;
159cdf0e10cSrcweir         if ( pSVData->maWinData.mpAppWin )
160cdf0e10cSrcweir             pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
161cdf0e10cSrcweir         return sal_True;
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     return sal_False;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // -----------------------------------------------------------------------
168cdf0e10cSrcweir 
EndExtHelp()169cdf0e10cSrcweir sal_Bool Help::EndExtHelp()
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     if ( pSVData->maHelpData.mbExtHelp && pSVData->maHelpData.mbExtHelpMode )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         pSVData->maHelpData.mbExtHelpMode = sal_False;
176cdf0e10cSrcweir         pSVData->maHelpData.mbBalloonHelp = pSVData->maHelpData.mbOldBalloonMode;
177cdf0e10cSrcweir         if ( pSVData->maWinData.mpAppWin )
178cdf0e10cSrcweir             pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
179cdf0e10cSrcweir         return sal_True;
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     return sal_False;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir // -----------------------------------------------------------------------
186cdf0e10cSrcweir 
IsExtHelpActive()187cdf0e10cSrcweir sal_Bool Help::IsExtHelpActive()
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     return ImplGetSVData()->maHelpData.mbExtHelpMode;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir // -----------------------------------------------------------------------
193cdf0e10cSrcweir 
EnableBalloonHelp()194cdf0e10cSrcweir void Help::EnableBalloonHelp()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbBalloonHelp = sal_True;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // -----------------------------------------------------------------------
200cdf0e10cSrcweir 
DisableBalloonHelp()201cdf0e10cSrcweir void Help::DisableBalloonHelp()
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbBalloonHelp = sal_False;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // -----------------------------------------------------------------------
207cdf0e10cSrcweir 
IsBalloonHelpEnabled()208cdf0e10cSrcweir sal_Bool Help::IsBalloonHelpEnabled()
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     return ImplGetSVData()->maHelpData.mbBalloonHelp;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir // -----------------------------------------------------------------------
214cdf0e10cSrcweir 
ShowBalloon(Window * pParent,const Point & rScreenPos,const XubString & rHelpText)215cdf0e10cSrcweir sal_Bool Help::ShowBalloon( Window* pParent,
216cdf0e10cSrcweir                         const Point& rScreenPos,
217cdf0e10cSrcweir                         const XubString& rHelpText )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, 0,
220cdf0e10cSrcweir                         rHelpText, ImplGetSVEmptyStr(), rScreenPos );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     return sal_True;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir // -----------------------------------------------------------------------
226cdf0e10cSrcweir 
ShowBalloon(Window * pParent,const Point & rScreenPos,const Rectangle & rRect,const XubString & rHelpText)227cdf0e10cSrcweir sal_Bool Help::ShowBalloon( Window* pParent,
228cdf0e10cSrcweir                         const Point& rScreenPos, const Rectangle& rRect,
229cdf0e10cSrcweir                         const XubString& rHelpText )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, 0,
232cdf0e10cSrcweir                         rHelpText, ImplGetSVEmptyStr(), rScreenPos, &rRect );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     return sal_True;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir // -----------------------------------------------------------------------
238cdf0e10cSrcweir 
EnableQuickHelp()239cdf0e10cSrcweir void Help::EnableQuickHelp()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbQuickHelp = sal_True;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir // -----------------------------------------------------------------------
245cdf0e10cSrcweir 
DisableQuickHelp()246cdf0e10cSrcweir void Help::DisableQuickHelp()
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mbQuickHelp = sal_False;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir // -----------------------------------------------------------------------
252cdf0e10cSrcweir 
IsQuickHelpEnabled()253cdf0e10cSrcweir sal_Bool Help::IsQuickHelpEnabled()
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     return ImplGetSVData()->maHelpData.mbQuickHelp;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir // -----------------------------------------------------------------------
259cdf0e10cSrcweir 
ShowQuickHelp(Window * pParent,const Rectangle & rScreenRect,const XubString & rHelpText,const XubString & rLongHelpText,sal_uInt16 nStyle)260cdf0e10cSrcweir sal_Bool Help::ShowQuickHelp( Window* pParent,
261cdf0e10cSrcweir                           const Rectangle& rScreenRect,
262cdf0e10cSrcweir                           const XubString& rHelpText,
263cdf0e10cSrcweir                           const XubString& rLongHelpText,
264cdf0e10cSrcweir                           sal_uInt16 nStyle )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir     ImplShowHelpWindow( pParent, HELPWINSTYLE_QUICK, nStyle,
267cdf0e10cSrcweir                         rHelpText, rLongHelpText,
268cdf0e10cSrcweir                         pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
269cdf0e10cSrcweir     return sal_True;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir // -----------------------------------------------------------------------
273cdf0e10cSrcweir 
HideBalloonAndQuickHelp()274cdf0e10cSrcweir void Help::HideBalloonAndQuickHelp()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir     HelpTextWindow const * pHelpWin = ImplGetSVData()->maHelpData.mpHelpWin;
277cdf0e10cSrcweir     bool const bIsVisible = ( pHelpWin != NULL ) && pHelpWin->IsVisible();
278cdf0e10cSrcweir     ImplDestroyHelpWindow( bIsVisible );
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir // -----------------------------------------------------------------------
282cdf0e10cSrcweir 
ShowTip(Window * pParent,const Rectangle & rScreenRect,const XubString & rText,sal_uInt16 nStyle)283cdf0e10cSrcweir sal_uIntPtr Help::ShowTip( Window* pParent, const Rectangle& rScreenRect,
284cdf0e10cSrcweir                      const XubString& rText, sal_uInt16 nStyle )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     sal_uInt16 nHelpWinStyle = ( ( nStyle & QUICKHELP_TIP_STYLE_BALLOON ) != 0 ) ? HELPWINSTYLE_BALLOON : HELPWINSTYLE_QUICK;
287cdf0e10cSrcweir     HelpTextWindow* pHelpWin = new HelpTextWindow( pParent, rText, nHelpWinStyle, nStyle );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir     sal_uIntPtr nId = reinterpret_cast< sal_uIntPtr >( pHelpWin );
290cdf0e10cSrcweir     UpdateTip( nId, pParent, rScreenRect, rText );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     pHelpWin->ShowHelp( HELPDELAY_NONE );
293cdf0e10cSrcweir     return nId;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir // -----------------------------------------------------------------------
297cdf0e10cSrcweir 
UpdateTip(sal_uIntPtr nId,Window * pParent,const Rectangle & rScreenRect,const XubString & rText)298cdf0e10cSrcweir void Help::UpdateTip( sal_uIntPtr nId, Window* pParent, const Rectangle& rScreenRect, const XubString& rText )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir     HelpTextWindow* pHelpWin = reinterpret_cast< HelpTextWindow* >( nId );
301cdf0e10cSrcweir     ENSURE_OR_RETURN_VOID( pHelpWin != NULL, "Help::UpdateTip: invalid ID!" );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     Size aSz = pHelpWin->CalcOutSize();
304cdf0e10cSrcweir     pHelpWin->SetOutputSizePixel( aSz );
305cdf0e10cSrcweir     ImplSetHelpWindowPos( pHelpWin, pHelpWin->GetWinStyle(), pHelpWin->GetStyle(),
306cdf0e10cSrcweir         pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     pHelpWin->SetHelpText( rText );
309cdf0e10cSrcweir     pHelpWin->Invalidate();
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir // -----------------------------------------------------------------------
313cdf0e10cSrcweir 
HideTip(sal_uLong nId)314cdf0e10cSrcweir void Help::HideTip( sal_uLong nId )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     HelpTextWindow* pHelpWin = (HelpTextWindow*)nId;
317cdf0e10cSrcweir     Window* pFrameWindow = pHelpWin->ImplGetFrameWindow();
318cdf0e10cSrcweir     pHelpWin->Hide();
3198898b9e3Smseidel     // Update auslösen, damit ein Paint sofort ausgelöst wird, da
320cdf0e10cSrcweir     // wir den Hintergrund nicht sichern
321cdf0e10cSrcweir     pFrameWindow->ImplUpdateAll();
322cdf0e10cSrcweir     delete pHelpWin;
323cdf0e10cSrcweir     ImplGetSVData()->maHelpData.mnLastHelpHideTime = Time::GetSystemTicks();
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir // =======================================================================
327cdf0e10cSrcweir 
HelpTextWindow(Window * pParent,const XubString & rText,sal_uInt16 nHelpWinStyle,sal_uInt16 nStyle)328cdf0e10cSrcweir HelpTextWindow::HelpTextWindow( Window* pParent, const XubString& rText, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle ) :
329cdf0e10cSrcweir     //FloatingWindow( pParent->ImplGetFrameWindow(), WB_SYSTEMWINDOW ),
330cdf0e10cSrcweir     FloatingWindow( pParent, WB_SYSTEMWINDOW|WB_TOOLTIPWIN ), // #105827# if we change the parent, mirroring will not work correctly when positioning this window
331cdf0e10cSrcweir     maHelpText( rText )
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     SetType( WINDOW_HELPTEXTWINDOW );
334cdf0e10cSrcweir     ImplSetMouseTransparent( sal_True );
335cdf0e10cSrcweir     mnHelpWinStyle = nHelpWinStyle;
336cdf0e10cSrcweir     mnStyle = nStyle;
3378898b9e3Smseidel // On Windows this will raise the application window, because help windows are system windows now
338cdf0e10cSrcweir //  EnableAlwaysOnTop();
339cdf0e10cSrcweir     EnableSaveBackground();
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
342cdf0e10cSrcweir     SetPointFont( rStyleSettings.GetHelpFont() );
343cdf0e10cSrcweir     SetTextColor( rStyleSettings.GetHelpTextColor() );
344cdf0e10cSrcweir     SetTextAlign( ALIGN_TOP );
345cdf0e10cSrcweir     if ( IsNativeControlSupported( CTRL_TOOLTIP, PART_ENTIRE_CONTROL ) )
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir         EnableChildTransparentMode( sal_True );
348cdf0e10cSrcweir         SetParentClipMode( PARENTCLIPMODE_NOCLIP );
349cdf0e10cSrcweir         SetPaintTransparent( sal_True );
350cdf0e10cSrcweir         SetBackground();
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir     else
353cdf0e10cSrcweir         SetBackground( Wallpaper( rStyleSettings.GetHelpColor() ) );
354cdf0e10cSrcweir     if( rStyleSettings.GetHelpColor().IsDark() )
3555793b69bSmseidel         SetLineColor( COL_YELLOW );
356cdf0e10cSrcweir     else
357cdf0e10cSrcweir         SetLineColor( COL_BLACK );
358cdf0e10cSrcweir     SetFillColor();
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     if( mnStyle & QUICKHELP_BIDI_RTL )
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir         sal_uLong nLayoutMode = GetLayoutMode();
363cdf0e10cSrcweir         nLayoutMode |= TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT;
364cdf0e10cSrcweir         SetLayoutMode( nLayoutMode );
365cdf0e10cSrcweir     }
366cdf0e10cSrcweir     SetHelpText( rText );
367cdf0e10cSrcweir     Window::SetHelpText( rText );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
370cdf0e10cSrcweir     if ( pSVData->maHelpData.mbSetKeyboardHelp )
371cdf0e10cSrcweir         pSVData->maHelpData.mbKeyboardHelp = sal_True;
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     const HelpSettings& rHelpSettings = pParent->GetSettings().GetHelpSettings();
374cdf0e10cSrcweir     maShowTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
375cdf0e10cSrcweir     maHideTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
376cdf0e10cSrcweir     maHideTimer.SetTimeout( rHelpSettings.GetTipTimeout() );
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir // -----------------------------------------------------------------------
380cdf0e10cSrcweir 
~HelpTextWindow()381cdf0e10cSrcweir HelpTextWindow::~HelpTextWindow()
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     maShowTimer.Stop();
384cdf0e10cSrcweir     maHideTimer.Stop();
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     if( this == ImplGetSVData()->maHelpData.mpHelpWin )
387cdf0e10cSrcweir         ImplGetSVData()->maHelpData.mpHelpWin = NULL;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     if ( maStatusText.Len() )
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         ImplSVData* pSVData = ImplGetSVData();
392cdf0e10cSrcweir         pSVData->mpApp->HideHelpStatusText();
393cdf0e10cSrcweir     }
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir // -----------------------------------------------------------------------
397cdf0e10cSrcweir 
SetHelpText(const String & rHelpText)398cdf0e10cSrcweir void HelpTextWindow::SetHelpText( const String& rHelpText )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir     maHelpText = rHelpText;
401*0406e650Smseidel     if ( mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.Len() < 100 )
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir         Size aSize;
404cdf0e10cSrcweir         aSize.Height() = GetTextHeight();
405cdf0e10cSrcweir         if ( mnStyle & QUICKHELP_CTRLTEXT )
406cdf0e10cSrcweir             aSize.Width() = GetCtrlTextWidth( maHelpText );
407cdf0e10cSrcweir         else
408cdf0e10cSrcweir             aSize.Width() = GetTextWidth( maHelpText );
409cdf0e10cSrcweir         maTextRect = Rectangle( Point( HELPTEXTMARGIN_QUICK, HELPTEXTMARGIN_QUICK ), aSize );
410cdf0e10cSrcweir     }
411cdf0e10cSrcweir     else // HELPWINSTYLE_BALLOON
412cdf0e10cSrcweir     {
413cdf0e10cSrcweir         Point       aTmpPoint;
414cdf0e10cSrcweir         sal_uInt16      nCharsInLine = 35 + ((maHelpText.Len()/100)*5);
415cdf0e10cSrcweir         XubString   aXXX;
4165793b69bSmseidel         aXXX.Fill( nCharsInLine, 'x' ); // average width for all windows
417cdf0e10cSrcweir         long nWidth = GetTextWidth( aXXX );
418cdf0e10cSrcweir         Size aTmpSize( nWidth, 0x7FFFFFFF );
419cdf0e10cSrcweir         Rectangle aTry1( aTmpPoint, aTmpSize );
420cdf0e10cSrcweir         sal_uInt16 nDrawFlags = TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK |
421cdf0e10cSrcweir                             TEXT_DRAW_LEFT | TEXT_DRAW_TOP;
422cdf0e10cSrcweir         if ( mnStyle & QUICKHELP_CTRLTEXT )
423cdf0e10cSrcweir             nDrawFlags |= TEXT_DRAW_MNEMONIC;
424cdf0e10cSrcweir         Rectangle aTextRect = GetTextRect( aTry1, maHelpText, nDrawFlags );
425cdf0e10cSrcweir 
4268898b9e3Smseidel         // Später mal eine geeignete Breite ermitteln...
427cdf0e10cSrcweir         maTextRect = aTextRect;
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         // Sicherheitsabstand...
430cdf0e10cSrcweir         maTextRect.SetPos( Point( HELPTEXTMARGIN_BALLOON, HELPTEXTMARGIN_BALLOON ) );
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     Size aSize( CalcOutSize() );
434cdf0e10cSrcweir     SetOutputSizePixel( aSize );
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir // -----------------------------------------------------------------------
438cdf0e10cSrcweir 
ImplShow()439cdf0e10cSrcweir void HelpTextWindow::ImplShow()
440cdf0e10cSrcweir {
441cdf0e10cSrcweir     ImplDelData aDogTag( this );
442cdf0e10cSrcweir     if ( maStatusText.Len() )
443cdf0e10cSrcweir     {
444cdf0e10cSrcweir         ImplSVData* pSVData = ImplGetSVData();
445cdf0e10cSrcweir         pSVData->mpApp->ShowHelpStatusText( maStatusText );
446cdf0e10cSrcweir     }
447cdf0e10cSrcweir     Show( sal_True, SHOW_NOACTIVATE );
448cdf0e10cSrcweir     if( !aDogTag.IsDelete() )
449cdf0e10cSrcweir     Update();
450cdf0e10cSrcweir }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir // -----------------------------------------------------------------------
453cdf0e10cSrcweir 
Paint(const Rectangle &)454cdf0e10cSrcweir void HelpTextWindow::Paint( const Rectangle& )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir     // paint native background
457cdf0e10cSrcweir     bool bNativeOK = false;
458cdf0e10cSrcweir     if ( IsNativeControlSupported( CTRL_TOOLTIP, PART_ENTIRE_CONTROL ) )
459cdf0e10cSrcweir     {
460cdf0e10cSrcweir         // #i46472# workaround gcc3.3 temporary problem
461cdf0e10cSrcweir         Rectangle aCtrlRegion( Point( 0, 0 ), GetOutputSizePixel() );
462cdf0e10cSrcweir         ImplControlValue aControlValue;
463cdf0e10cSrcweir         bNativeOK = DrawNativeControl( CTRL_TOOLTIP, PART_ENTIRE_CONTROL, aCtrlRegion,
464cdf0e10cSrcweir                                        0, aControlValue, rtl::OUString() );
465cdf0e10cSrcweir     }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir     // paint text
468*0406e650Smseidel     if ( mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.Len() < 100 )
469cdf0e10cSrcweir     {
470cdf0e10cSrcweir         if ( mnStyle & QUICKHELP_CTRLTEXT )
471cdf0e10cSrcweir             DrawCtrlText( maTextRect.TopLeft(), maHelpText );
472cdf0e10cSrcweir         else
473cdf0e10cSrcweir             DrawText( maTextRect.TopLeft(), maHelpText );
474cdf0e10cSrcweir     }
475cdf0e10cSrcweir     else // HELPWINSTYLE_BALLOON
476cdf0e10cSrcweir     {
477cdf0e10cSrcweir         sal_uInt16 nDrawFlags = TEXT_DRAW_MULTILINE|TEXT_DRAW_WORDBREAK|
478cdf0e10cSrcweir                                 TEXT_DRAW_LEFT|TEXT_DRAW_TOP;
479cdf0e10cSrcweir         if ( mnStyle & QUICKHELP_CTRLTEXT )
480cdf0e10cSrcweir             nDrawFlags |= TEXT_DRAW_MNEMONIC;
481cdf0e10cSrcweir         DrawText( maTextRect, maHelpText, nDrawFlags );
482cdf0e10cSrcweir     }
483cdf0e10cSrcweir 
4848898b9e3Smseidel     // paint border
485cdf0e10cSrcweir     if( ! bNativeOK )
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir         Size aSz = GetOutputSizePixel();
488cdf0e10cSrcweir         DrawRect( Rectangle( Point(), aSz ) );
489*0406e650Smseidel //      if ( mnHelpWinStyle == HELPWINSTYLE_BALLOON ) // same border as quickhelp
4908898b9e3Smseidel //      {
4918898b9e3Smseidel //          aSz.Width() -= 2;
4928898b9e3Smseidel //          aSz.Height() -= 2;
4938898b9e3Smseidel //          Color aColor( GetLineColor() );
4948898b9e3Smseidel //          SetLineColor( ( COL_GRAY ) );
4958898b9e3Smseidel //          DrawRect( Rectangle( Point( 1, 1 ), aSz ) );
4968898b9e3Smseidel //          SetLineColor( aColor );
4978898b9e3Smseidel //      }
498cdf0e10cSrcweir     }
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir // -----------------------------------------------------------------------
502cdf0e10cSrcweir 
ShowHelp(sal_uInt16 nDelayMode)503cdf0e10cSrcweir void HelpTextWindow::ShowHelp( sal_uInt16 nDelayMode )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir     sal_uLong nTimeout = 0;
506cdf0e10cSrcweir     if ( nDelayMode != HELPDELAY_NONE )
507cdf0e10cSrcweir     {
508cdf0e10cSrcweir         // Im ExtendedHelp-Fall die Hilfe schneller anzeigen
509cdf0e10cSrcweir         if ( ImplGetSVData()->maHelpData.mbExtHelpMode )
510cdf0e10cSrcweir             nTimeout = 15;
511cdf0e10cSrcweir         else
512cdf0e10cSrcweir         {
513cdf0e10cSrcweir             const HelpSettings& rHelpSettings = GetSettings().GetHelpSettings();
514cdf0e10cSrcweir             if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
515cdf0e10cSrcweir                 nTimeout = rHelpSettings.GetTipDelay();
516cdf0e10cSrcweir             else
517cdf0e10cSrcweir                 nTimeout = rHelpSettings.GetBalloonDelay();
518cdf0e10cSrcweir         }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir         if ( nDelayMode == HELPDELAY_SHORT )
521cdf0e10cSrcweir             nTimeout /= 3;
522cdf0e10cSrcweir     }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir     maShowTimer.SetTimeout( nTimeout );
525cdf0e10cSrcweir     maShowTimer.Start();
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir // -----------------------------------------------------------------------
529cdf0e10cSrcweir 
IMPL_LINK(HelpTextWindow,TimerHdl,Timer *,pTimer)530cdf0e10cSrcweir IMPL_LINK( HelpTextWindow, TimerHdl, Timer*, pTimer)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir     if ( pTimer == &maShowTimer )
533cdf0e10cSrcweir     {
534cdf0e10cSrcweir         if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
535cdf0e10cSrcweir         {
536cdf0e10cSrcweir             // start auto-hide-timer for non-ShowTip windows
537cdf0e10cSrcweir             ImplSVData* pSVData = ImplGetSVData();
538cdf0e10cSrcweir             if ( this == pSVData->maHelpData.mpHelpWin )
539cdf0e10cSrcweir                 maHideTimer.Start();
540cdf0e10cSrcweir         }
541cdf0e10cSrcweir         ImplShow();
542cdf0e10cSrcweir     }
543cdf0e10cSrcweir     else
544cdf0e10cSrcweir     {
545cdf0e10cSrcweir         DBG_ASSERT( pTimer == &maHideTimer, "HelpTextWindow::TimerHdl with bad Timer" );
546cdf0e10cSrcweir         ImplDestroyHelpWindow( true );
547cdf0e10cSrcweir     }
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     return 1;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir // -----------------------------------------------------------------------
553cdf0e10cSrcweir 
CalcOutSize() const554cdf0e10cSrcweir Size HelpTextWindow::CalcOutSize() const
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     Size aSz = maTextRect.GetSize();
557cdf0e10cSrcweir     aSz.Width() += 2*maTextRect.Left();
558cdf0e10cSrcweir     aSz.Height() += 2*maTextRect.Top();
559cdf0e10cSrcweir     return aSz;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir 
562cdf0e10cSrcweir // -----------------------------------------------------------------------
563cdf0e10cSrcweir 
RequestHelp(const HelpEvent &)564cdf0e10cSrcweir void HelpTextWindow::RequestHelp( const HelpEvent& /*rHEvt*/ )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir     // Nur damit nicht von Window::RequestHelp() ein
567cdf0e10cSrcweir     // ShowQuickHelp/ShowBalloonHelp am HelpTextWindow aufgerufen wird.
568cdf0e10cSrcweir }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir // -----------------------------------------------------------------------
571cdf0e10cSrcweir 
GetText() const572cdf0e10cSrcweir String HelpTextWindow::GetText() const
573cdf0e10cSrcweir {
574cdf0e10cSrcweir     return maHelpText;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir // -----------------------------------------------------------------------
578cdf0e10cSrcweir 
CreateAccessible()579cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > HelpTextWindow::CreateAccessible()
580cdf0e10cSrcweir {
581cdf0e10cSrcweir     return FloatingWindow::CreateAccessible();
582cdf0e10cSrcweir }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir // -----------------------------------------------------------------------
585cdf0e10cSrcweir 
RegisterAccessibleParent()586cdf0e10cSrcweir sal_Bool HelpTextWindow::RegisterAccessibleParent()
587cdf0e10cSrcweir {
588cdf0e10cSrcweir         return sal_False;
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir // -----------------------------------------------------------------------
592cdf0e10cSrcweir 
RevokeAccessibleParent()593cdf0e10cSrcweir void HelpTextWindow::RevokeAccessibleParent()
594cdf0e10cSrcweir {
595cdf0e10cSrcweir }
596cdf0e10cSrcweir 
597cdf0e10cSrcweir // =======================================================================
598cdf0e10cSrcweir 
ImplShowHelpWindow(Window * pParent,sal_uInt16 nHelpWinStyle,sal_uInt16 nStyle,const XubString & rHelpText,const XubString & rStatusText,const Point & rScreenPos,const Rectangle * pHelpArea)599cdf0e10cSrcweir void ImplShowHelpWindow( Window* pParent, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle,
600cdf0e10cSrcweir                          const XubString& rHelpText, const XubString& rStatusText,
601cdf0e10cSrcweir                          const Point& rScreenPos, const Rectangle* pHelpArea )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
604cdf0e10cSrcweir 
605cdf0e10cSrcweir     if( !rHelpText.Len() && !pSVData->maHelpData.mbRequestingHelp )
606cdf0e10cSrcweir         return;
607cdf0e10cSrcweir 
608cdf0e10cSrcweir     HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin;
609cdf0e10cSrcweir     sal_uInt16 nDelayMode = HELPDELAY_NORMAL;
610cdf0e10cSrcweir     if ( pHelpWin )
611cdf0e10cSrcweir     {
612cdf0e10cSrcweir         DBG_ASSERT( pHelpWin != pParent, "HelpInHelp ?!" );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir         if  (   (   ( pHelpWin->GetHelpText() != rHelpText )
615cdf0e10cSrcweir                 ||  ( pHelpWin->GetWinStyle() != nHelpWinStyle )
616cdf0e10cSrcweir                 ||  (   pHelpArea
617cdf0e10cSrcweir                     &&  ( pHelpWin->GetHelpArea() != *pHelpArea )
618cdf0e10cSrcweir                     )
619cdf0e10cSrcweir                 )
620cdf0e10cSrcweir             &&  pSVData->maHelpData.mbRequestingHelp
621cdf0e10cSrcweir             )
622cdf0e10cSrcweir         {
623cdf0e10cSrcweir             // remove help window if no HelpText or other HelpText or
6248898b9e3Smseidel             // other help mode. but keep it if we are scrolling, i.e. not requesting help
625cdf0e10cSrcweir             bool bWasVisible = pHelpWin->IsVisible();
626cdf0e10cSrcweir             if ( bWasVisible )
627cdf0e10cSrcweir                 nDelayMode = HELPDELAY_NONE; // display it quickly if we were already in quick help mode
628cdf0e10cSrcweir             pHelpWin = NULL;
629cdf0e10cSrcweir             ImplDestroyHelpWindow( bWasVisible );
630cdf0e10cSrcweir         }
631cdf0e10cSrcweir         else
632cdf0e10cSrcweir         {
633cdf0e10cSrcweir             bool const bTextChanged = rHelpText != pHelpWin->GetHelpText();
634cdf0e10cSrcweir             if ( bTextChanged || ( ( nStyle & QUICKHELP_FORCE_REPOSITION ) != 0 ) )
635cdf0e10cSrcweir             {
636cdf0e10cSrcweir                 Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
637cdf0e10cSrcweir                 Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
638cdf0e10cSrcweir                 if( pHelpWin->IsVisible() )
639cdf0e10cSrcweir                     pWindow->Invalidate( aInvRect );
640cdf0e10cSrcweir 
641cdf0e10cSrcweir                 pHelpWin->SetHelpText( rHelpText );
642cdf0e10cSrcweir                 // approach mouse position
643cdf0e10cSrcweir                 ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
644cdf0e10cSrcweir                 if( pHelpWin->IsVisible() )
645cdf0e10cSrcweir                     pHelpWin->Invalidate();
646cdf0e10cSrcweir             }
647cdf0e10cSrcweir         }
648cdf0e10cSrcweir     }
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     if ( !pHelpWin && rHelpText.Len() )
651cdf0e10cSrcweir     {
652cdf0e10cSrcweir         sal_uLong nCurTime = Time::GetSystemTicks();
653cdf0e10cSrcweir         if  (   ( ( nCurTime - pSVData->maHelpData.mnLastHelpHideTime ) < pParent->GetSettings().GetHelpSettings().GetTipDelay() )
654cdf0e10cSrcweir             ||  ( ( nStyle & QUICKHELP_NO_DELAY ) != 0 )
655cdf0e10cSrcweir             )
656cdf0e10cSrcweir             nDelayMode = HELPDELAY_NONE;
657cdf0e10cSrcweir 
6585793b69bSmseidel         DBG_ASSERT( !pHelpWin, "Another HelpWin?!" );
659cdf0e10cSrcweir         pHelpWin = new HelpTextWindow( pParent, rHelpText, nHelpWinStyle, nStyle );
660cdf0e10cSrcweir         pSVData->maHelpData.mpHelpWin = pHelpWin;
661cdf0e10cSrcweir         pHelpWin->SetStatusText( rStatusText );
662cdf0e10cSrcweir         if ( pHelpArea )
663cdf0e10cSrcweir             pHelpWin->SetHelpArea( *pHelpArea );
664cdf0e10cSrcweir 
665cdf0e10cSrcweir         // positioning
666cdf0e10cSrcweir         Size aSz = pHelpWin->CalcOutSize();
667cdf0e10cSrcweir         pHelpWin->SetOutputSizePixel( aSz );
668cdf0e10cSrcweir         ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
669cdf0e10cSrcweir         // if not called from Window::RequestHelp, then without delay...
670cdf0e10cSrcweir         if ( !pSVData->maHelpData.mbRequestingHelp )
671cdf0e10cSrcweir             nDelayMode = HELPDELAY_NONE;
672cdf0e10cSrcweir         pHelpWin->ShowHelp( nDelayMode );
673cdf0e10cSrcweir     }
674cdf0e10cSrcweir }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir // -----------------------------------------------------------------------
677cdf0e10cSrcweir 
ImplDestroyHelpWindow(bool bUpdateHideTime)678cdf0e10cSrcweir void ImplDestroyHelpWindow( bool bUpdateHideTime )
679cdf0e10cSrcweir {
680cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
681cdf0e10cSrcweir     HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin;
682cdf0e10cSrcweir     if ( pHelpWin )
683cdf0e10cSrcweir     {
684cdf0e10cSrcweir         Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
685cdf0e10cSrcweir         // find out screen area covered by system help window
686cdf0e10cSrcweir         Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
687cdf0e10cSrcweir         if( pHelpWin->IsVisible() )
688cdf0e10cSrcweir             pWindow->Invalidate( aInvRect );
689cdf0e10cSrcweir         pSVData->maHelpData.mpHelpWin = NULL;
690cdf0e10cSrcweir         pSVData->maHelpData.mbKeyboardHelp = sal_False;
691cdf0e10cSrcweir         pHelpWin->Hide();
692cdf0e10cSrcweir         delete pHelpWin;
693cdf0e10cSrcweir         if( bUpdateHideTime )
694cdf0e10cSrcweir             pSVData->maHelpData.mnLastHelpHideTime = Time::GetSystemTicks();
695cdf0e10cSrcweir     }
696cdf0e10cSrcweir }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir // -----------------------------------------------------------------------
699cdf0e10cSrcweir 
ImplSetHelpWindowPos(Window * pHelpWin,sal_uInt16 nHelpWinStyle,sal_uInt16 nStyle,const Point & rPos,const Rectangle * pHelpArea)700cdf0e10cSrcweir void ImplSetHelpWindowPos( Window* pHelpWin, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle,
701cdf0e10cSrcweir                            const Point& rPos, const Rectangle* pHelpArea )
702cdf0e10cSrcweir {
703cdf0e10cSrcweir     Point       aPos = rPos;
704cdf0e10cSrcweir     Size        aSz = pHelpWin->GetSizePixel();
705cdf0e10cSrcweir     Rectangle   aScreenRect = pHelpWin->ImplGetFrameWindow()->GetDesktopRectPixel();
706cdf0e10cSrcweir     aPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( aPos );
7075793b69bSmseidel     // get mouse screen coordinates
708cdf0e10cSrcweir     Point mPos( pHelpWin->GetParent()->ImplGetFrameWindow()->GetPointerPosPixel() );
709cdf0e10cSrcweir     mPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( mPos );
710cdf0e10cSrcweir 
711cdf0e10cSrcweir     if ( nHelpWinStyle == HELPWINSTYLE_QUICK )
712cdf0e10cSrcweir     {
713cdf0e10cSrcweir         if ( !(nStyle & QUICKHELP_NOAUTOPOS) )
714cdf0e10cSrcweir         {
715cdf0e10cSrcweir             long nScreenHeight = aScreenRect.GetHeight();
716cdf0e10cSrcweir             aPos.X() -= 4;
717cdf0e10cSrcweir             if ( aPos.Y() > aScreenRect.Top()+nScreenHeight-(nScreenHeight/4) )
718cdf0e10cSrcweir                 aPos.Y() -= aSz.Height()+4;
719cdf0e10cSrcweir             else
720cdf0e10cSrcweir                 aPos.Y() += 21;
721cdf0e10cSrcweir         }
722cdf0e10cSrcweir     }
723cdf0e10cSrcweir     else
724cdf0e10cSrcweir     {
725cdf0e10cSrcweir         // If it's the mouse position, move the window slightly
726cdf0e10cSrcweir         // so the mouse pointer does not cover it
727cdf0e10cSrcweir         if ( aPos == mPos )
728cdf0e10cSrcweir         {
729cdf0e10cSrcweir             aPos.X() += 12;
730cdf0e10cSrcweir             aPos.Y() += 16;
731cdf0e10cSrcweir         }
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir 
734cdf0e10cSrcweir     if ( nStyle & QUICKHELP_NOAUTOPOS )
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         if ( pHelpArea )
737cdf0e10cSrcweir         {
7385793b69bSmseidel             // convert help area to screen coordinates
739cdf0e10cSrcweir             Rectangle devHelpArea(
740cdf0e10cSrcweir                 pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->TopLeft() ),
741cdf0e10cSrcweir                 pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->BottomRight() ) );
742cdf0e10cSrcweir 
743cdf0e10cSrcweir             // Welche Position vom Rechteck?
744cdf0e10cSrcweir             aPos = devHelpArea.Center();
745cdf0e10cSrcweir 
746cdf0e10cSrcweir             if ( nStyle & QUICKHELP_LEFT )
747cdf0e10cSrcweir                 aPos.X() = devHelpArea.Left();
748cdf0e10cSrcweir             else if ( nStyle & QUICKHELP_RIGHT )
749cdf0e10cSrcweir                 aPos.X() = devHelpArea.Right();
750cdf0e10cSrcweir 
751cdf0e10cSrcweir             if ( nStyle & QUICKHELP_TOP )
752cdf0e10cSrcweir                 aPos.Y() = devHelpArea.Top();
753cdf0e10cSrcweir             else if ( nStyle & QUICKHELP_BOTTOM )
754cdf0e10cSrcweir                 aPos.Y() = devHelpArea.Bottom();
755cdf0e10cSrcweir         }
756cdf0e10cSrcweir 
757*0406e650Smseidel         // Which direction?
758cdf0e10cSrcweir         if ( nStyle & QUICKHELP_LEFT )
759cdf0e10cSrcweir             ;
760cdf0e10cSrcweir         else if ( nStyle & QUICKHELP_RIGHT )
761cdf0e10cSrcweir             aPos.X() -= aSz.Width();
762cdf0e10cSrcweir         else
763cdf0e10cSrcweir             aPos.X() -= aSz.Width() / 2;
764cdf0e10cSrcweir 
765cdf0e10cSrcweir         if ( nStyle & QUICKHELP_TOP )
766cdf0e10cSrcweir             ;
767cdf0e10cSrcweir         else if ( nStyle & QUICKHELP_BOTTOM )
768cdf0e10cSrcweir             aPos.Y() -= aSz.Height();
769cdf0e10cSrcweir         else
770cdf0e10cSrcweir             aPos.Y() -= aSz.Height() / 2;
771cdf0e10cSrcweir     }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir     if ( aPos.X() < aScreenRect.Left() )
774cdf0e10cSrcweir         aPos.X() = aScreenRect.Left();
775cdf0e10cSrcweir     else if ( ( aPos.X() + aSz.Width() ) > aScreenRect.Right() )
776cdf0e10cSrcweir         aPos.X() = aScreenRect.Right() - aSz.Width();
777cdf0e10cSrcweir     if ( aPos.Y() < aScreenRect.Top() )
778cdf0e10cSrcweir         aPos.Y() = aScreenRect.Top();
779cdf0e10cSrcweir     else if ( ( aPos.Y() + aSz.Height() ) > aScreenRect.Bottom() )
780cdf0e10cSrcweir         aPos.Y() = aScreenRect.Bottom() - aSz.Height();
781cdf0e10cSrcweir 
782cdf0e10cSrcweir     if( ! (nStyle & QUICKHELP_NOEVADEPOINTER) )
783cdf0e10cSrcweir     {
784cdf0e10cSrcweir         /* the remark below should be obsolete by now as the helpwindow should
785cdf0e10cSrcweir         not be focusable, leaving it as a hint. However it is sensible in most
786cdf0e10cSrcweir         conditions to evade the mouse pointer so the content window is fully visible.
787cdf0e10cSrcweir 
788cdf0e10cSrcweir         // the popup must not appear under the mouse
789cdf0e10cSrcweir         // otherwise it would directly be closed due to a focus change...
790cdf0e10cSrcweir         */
791cdf0e10cSrcweir         Rectangle aHelpRect( aPos, aSz );
792cdf0e10cSrcweir         if( aHelpRect.IsInside( mPos ) )
793cdf0e10cSrcweir         {
794cdf0e10cSrcweir             Point delta(2,2);
795cdf0e10cSrcweir             Point pSize( aSz.Width(), aSz.Height() );
796cdf0e10cSrcweir             Point pTest( mPos - pSize - delta );
797cdf0e10cSrcweir             if( pTest.X() > aScreenRect.Left() && pTest.Y() > aScreenRect.Top() )
798cdf0e10cSrcweir                 aPos = pTest;
799cdf0e10cSrcweir             else
800cdf0e10cSrcweir                 aPos = mPos + delta;
801cdf0e10cSrcweir         }
802cdf0e10cSrcweir     }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir     Window* pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
805cdf0e10cSrcweir     aPos = pWindow->AbsoluteScreenToOutputPixel( aPos );
806cdf0e10cSrcweir     pHelpWin->SetPosPixel( aPos );
807cdf0e10cSrcweir }
8088898b9e3Smseidel 
8098898b9e3Smseidel /* vim: set noet sw=4 ts=4: */
810