1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helpagentwindow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include "helpagentwindow.hxx"
34 #include <osl/diagnose.h>
35 #ifndef _SV_BUTTON_HXX
36 #include <vcl/button.hxx>
38 #include <vcl/bitmap.hxx>
39 #include <svtools/svtdata.hxx>
42 #include <svtools/svtools.hrc>
44 #ifndef _SVT_HELPID_HRC
45 #include <svtools/helpid.hrc>
48 #define WB_AGENT_STYLE 0
50 //........................................................................
53 //........................................................................
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::lang
;
58 //====================================================================
60 //= overload of ImageButton, because sometimes vcl doesn't call the click handler
61 //====================================================================
62 //--------------------------------------------------------------------
63 class CloserButton_Impl
: public ImageButton
66 CloserButton_Impl( Window
* pParent
, WinBits nBits
) : ImageButton( pParent
, nBits
) {}
68 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
71 //--------------------------------------------------------------------
72 void CloserButton_Impl::MouseButtonUp( const MouseEvent
& rMEvt
)
74 ImageButton::MouseButtonUp( rMEvt
);
75 GetClickHdl().Call( this );
78 //====================================================================
80 //====================================================================
81 //--------------------------------------------------------------------
82 HelpAgentWindow::HelpAgentWindow( Window
* _pParent
)
83 :FloatingWindow( _pParent
, WB_AGENT_STYLE
)
89 Bitmap
aCloserBitmap(SvtResId(BMP_HELP_AGENT_CLOSER
));
90 Image
aCloserImage( aCloserBitmap
, Color(COL_LIGHTMAGENTA
) );
91 m_pCloser
= new CloserButton_Impl( this, WB_NOTABSTOP
| WB_NOPOINTERFOCUS
);
92 static_cast<CloserButton_Impl
*>(m_pCloser
)->SetModeImage( aCloserImage
);
93 static_cast<CloserButton_Impl
*>(m_pCloser
)->SetClickHdl( LINK(this, HelpAgentWindow
, OnButtonClicked
) );
94 m_pCloser
->SetSizePixel( implOptimalButtonSize(aCloserImage
) );
96 m_pCloser
->SetZOrder( NULL
, WINDOW_ZORDER_LAST
);
98 // ----------------------------
99 // calculate our preferred size
100 Bitmap
aHelpAgentBitmap(SvtResId(BMP_HELP_AGENT_IMAGE
));
101 m_aPicture
= Image( aHelpAgentBitmap
);
102 m_aPreferredSize
= m_aPicture
.GetSizePixel();
103 m_aPreferredSize
.Width() += 2;
104 m_aPreferredSize
.Height() += 2;
106 Size aSize
= GetSizePixel();
107 Size aOutputSize
= GetOutputSizePixel();
108 m_aPreferredSize
.Width() += aSize
.Width() - aOutputSize
.Width();
109 m_aPreferredSize
.Height() += aSize
.Height() - aOutputSize
.Height();
111 SetPointer(Pointer(POINTER_REFHAND
));
112 AlwaysEnableInput( TRUE
, TRUE
);
114 // unique id for the testtool
115 SetUniqueId( HID_HELPAGENT_WINDOW
);
118 //--------------------------------------------------------------------
119 HelpAgentWindow::~HelpAgentWindow()
121 if (m_pCloser
&& m_pCloser
->IsTracking())
122 m_pCloser
->EndTracking();
123 if (m_pCloser
&& m_pCloser
->IsMouseCaptured())
124 m_pCloser
->ReleaseMouse();
129 //--------------------------------------------------------------------
130 void HelpAgentWindow::Paint( const Rectangle
& rRect
)
132 FloatingWindow::Paint(rRect
);
134 Size
aOutputSize( GetOutputSizePixel() );
135 Point aPoint
=Point();
136 Rectangle
aOutputRect( aPoint
, aOutputSize
);
137 Rectangle
aInnerRect( aOutputRect
);
139 // paint the background
140 SetLineColor( GetSettings().GetStyleSettings().GetFaceColor() );
141 SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() );
142 DrawRect( aOutputRect
);
145 Size
aPictureSize( m_aPicture
.GetSizePixel() );
147 aOutputRect
.Left() + (aInnerRect
.GetWidth() - aPictureSize
.Width()) / 2,
148 aOutputRect
.Top() + (aInnerRect
.GetHeight() - aPictureSize
.Height()) / 2 );
150 DrawImage( aPicturePos
, m_aPicture
, 0 );
153 //--------------------------------------------------------------------
154 void HelpAgentWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
156 FloatingWindow::MouseButtonUp(rMEvt
);
159 m_pCallback
->helpRequested();
162 //--------------------------------------------------------------------
163 Size
HelpAgentWindow::implOptimalButtonSize( const Image
& _rButtonImage
)
165 Size aPreferredSize
= _rButtonImage
.GetSizePixel();
166 // add a small frame, needed by the button
167 aPreferredSize
.Width() += 5;
168 aPreferredSize
.Height() += 5;
169 return aPreferredSize
;
172 //--------------------------------------------------------------------
173 void HelpAgentWindow::Resize()
175 FloatingWindow::Resize();
177 Size aOutputSize
= GetOutputSizePixel();
178 Size aCloserSize
= m_pCloser
->GetSizePixel();
180 m_pCloser
->SetPosPixel( Point(aOutputSize
.Width() - aCloserSize
.Width() - 3, 4) );
183 //--------------------------------------------------------------------
184 IMPL_LINK( HelpAgentWindow
, OnButtonClicked
, Window
*, _pWhichOne
)
186 if (m_pCloser
== _pWhichOne
)
188 m_pCallback
->closeAgent();
192 //........................................................................
194 //........................................................................