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