1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 #include <svtools/helpagentwindow.hxx>
27 #include <osl/diagnose.h>
28 #include <vcl/button.hxx>
29 #include <vcl/bitmap.hxx>
30 #include <svtools/svtdata.hxx>
31 #include <svtools/svtools.hrc>
32 #include <svtools/helpid.hrc>
33 
34 #define WB_AGENT_STYLE	0
35 
36 //........................................................................
37 namespace svt
38 {
39 //........................................................................
40 
41 	using namespace ::com::sun::star::uno;
42 	using namespace ::com::sun::star::lang;
43 
44 	//====================================================================
45 	//= CloserButton_Impl
46 	//= overload of ImageButton, because sometimes vcl doesn't call the click handler
47 	//====================================================================
48 	//--------------------------------------------------------------------
49 	class CloserButton_Impl : public ImageButton
50 	{
51 	public:
CloserButton_Impl(Window * pParent,WinBits nBits)52 		CloserButton_Impl( Window* pParent, WinBits nBits ) : ImageButton( pParent, nBits ) {}
53 
54 		virtual void		MouseButtonUp( const MouseEvent& rMEvt );
55 	};
56 
57 	//--------------------------------------------------------------------
MouseButtonUp(const MouseEvent & rMEvt)58 	void CloserButton_Impl::MouseButtonUp( const MouseEvent& rMEvt )
59 	{
60 		ImageButton::MouseButtonUp( rMEvt );
61 		GetClickHdl().Call( this );
62 	}
63 
64 	//====================================================================
65 	//= HelpAgentWindow
66 	//====================================================================
67 	//--------------------------------------------------------------------
HelpAgentWindow(Window * _pParent)68 	HelpAgentWindow::HelpAgentWindow( Window* _pParent )
69 		:FloatingWindow( _pParent, WB_AGENT_STYLE)
70 		,m_pCloser(NULL)
71 		,m_pCallback(NULL)
72 	{
73 		// -----------------
74 		// the closer button
75 		Bitmap aCloserBitmap(SvtResId(BMP_HELP_AGENT_CLOSER));
76 		Image aCloserImage( aCloserBitmap, Color(COL_BLACK) );
77 		m_pCloser = new CloserButton_Impl( this, WB_NOTABSTOP | WB_NOPOINTERFOCUS );
78 		static_cast<CloserButton_Impl*>(m_pCloser)->SetModeImage( aCloserImage );
79 		static_cast<CloserButton_Impl*>(m_pCloser)->SetClickHdl( LINK(this, HelpAgentWindow, OnButtonClicked) );
80 		m_pCloser->SetSizePixel( implOptimalButtonSize(aCloserImage) );
81 		m_pCloser->Show();
82 		m_pCloser->SetZOrder( NULL, WINDOW_ZORDER_LAST );
83 
84 		// ----------------------------
85 		// calculate our preferred size
86 		Bitmap aHelpAgentBitmap(SvtResId(BMP_HELP_AGENT_IMAGE));
87 		m_aPicture = Image( aHelpAgentBitmap );
88 		m_aPreferredSize = m_aPicture.GetSizePixel();
89 		m_aPreferredSize.Width() += 2;
90 		m_aPreferredSize.Height() += 2;
91 
92 		Size aSize = GetSizePixel();
93 		Size aOutputSize = GetOutputSizePixel();
94 		m_aPreferredSize.Width() += aSize.Width() - aOutputSize.Width();
95 		m_aPreferredSize.Height() += aSize.Height() - aOutputSize.Height();
96 
97 		SetPointer(Pointer(POINTER_REFHAND));
98 		AlwaysEnableInput( sal_True, sal_True );
99 
100 		// unique id for the testtool
101 		SetUniqueId( HID_HELPAGENT_WINDOW );
102 	}
103 
104 	//--------------------------------------------------------------------
~HelpAgentWindow()105 	HelpAgentWindow::~HelpAgentWindow()
106 	{
107 		if (m_pCloser && m_pCloser->IsTracking())
108 			m_pCloser->EndTracking();
109 		if (m_pCloser && m_pCloser->IsMouseCaptured())
110 			m_pCloser->ReleaseMouse();
111 
112 		delete m_pCloser;
113 	}
114 
115 	//--------------------------------------------------------------------
Paint(const Rectangle & rRect)116 	void HelpAgentWindow::Paint( const Rectangle& rRect )
117 	{
118 		FloatingWindow::Paint(rRect);
119 
120 		Size		aOutputSize( GetOutputSizePixel() );
121 		Point		aPoint=Point();
122 		Rectangle	aOutputRect( aPoint, aOutputSize );
123 		Rectangle	aInnerRect( aOutputRect );
124 
125 		// paint the background
126 		SetLineColor( GetSettings().GetStyleSettings().GetFaceColor() );
127 		SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() );
128 		DrawRect( aOutputRect );
129 
130 		// paint the image
131 		Size aPictureSize( m_aPicture.GetSizePixel() );
132 		Point aPicturePos(
133 			aOutputRect.Left() + (aInnerRect.GetWidth() - aPictureSize.Width()) / 2,
134 			aOutputRect.Top() + (aInnerRect.GetHeight() - aPictureSize.Height()) / 2 );
135 
136 		DrawImage( aPicturePos, m_aPicture, 0 );
137 	}
138 
139 	//--------------------------------------------------------------------
MouseButtonUp(const MouseEvent & rMEvt)140 	void HelpAgentWindow::MouseButtonUp( const MouseEvent& rMEvt )
141 	{
142 		FloatingWindow::MouseButtonUp(rMEvt);
143 
144 		if (m_pCallback)
145 			m_pCallback->helpRequested();
146 	}
147 
148 	//--------------------------------------------------------------------
implOptimalButtonSize(const Image & _rButtonImage)149 	Size HelpAgentWindow::implOptimalButtonSize( const Image& _rButtonImage )
150 	{
151 		Size aPreferredSize = _rButtonImage.GetSizePixel();
152 		// add a small frame, needed by the button
153 		aPreferredSize.Width() += 8;
154 		aPreferredSize.Height() += 8;
155 		return aPreferredSize;
156 	}
157 
158 	//--------------------------------------------------------------------
Resize()159 	void HelpAgentWindow::Resize()
160 	{
161 		FloatingWindow::Resize();
162 
163 		Size aOutputSize = GetOutputSizePixel();
164 		Size aCloserSize = m_pCloser->GetSizePixel();
165 		if (m_pCloser)
166 			m_pCloser->SetPosPixel( Point(aOutputSize.Width() - aCloserSize.Width() - 2, 2) );
167 	}
168 
169 	//--------------------------------------------------------------------
IMPL_LINK(HelpAgentWindow,OnButtonClicked,Window *,_pWhichOne)170 	IMPL_LINK( HelpAgentWindow, OnButtonClicked, Window*, _pWhichOne )
171 	{
172 		if (m_pCloser == _pWhichOne)
173 			if (m_pCallback)
174 				m_pCallback->closeAgent();
175 		return 0L;
176 	}
177 
178 //........................................................................
179 }	// namespace svt
180 //........................................................................
181 
182