1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svtools.hxx" 30 #include <svtools/helpagentwindow.hxx> 31 #include <osl/diagnose.h> 32 #include <vcl/button.hxx> 33 #include <vcl/bitmap.hxx> 34 #include <svtools/svtdata.hxx> 35 #include <svtools/svtools.hrc> 36 #include <svtools/helpid.hrc> 37 38 #define WB_AGENT_STYLE 0 39 40 //........................................................................ 41 namespace svt 42 { 43 //........................................................................ 44 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::lang; 47 48 //==================================================================== 49 //= CloserButton_Impl 50 //= overload of ImageButton, because sometimes vcl doesn't call the click handler 51 //==================================================================== 52 //-------------------------------------------------------------------- 53 class CloserButton_Impl : public ImageButton 54 { 55 public: 56 CloserButton_Impl( Window* pParent, WinBits nBits ) : ImageButton( pParent, nBits ) {} 57 58 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 59 }; 60 61 //-------------------------------------------------------------------- 62 void CloserButton_Impl::MouseButtonUp( const MouseEvent& rMEvt ) 63 { 64 ImageButton::MouseButtonUp( rMEvt ); 65 GetClickHdl().Call( this ); 66 } 67 68 //==================================================================== 69 //= HelpAgentWindow 70 //==================================================================== 71 //-------------------------------------------------------------------- 72 HelpAgentWindow::HelpAgentWindow( Window* _pParent ) 73 :FloatingWindow( _pParent, WB_AGENT_STYLE) 74 ,m_pCloser(NULL) 75 ,m_pCallback(NULL) 76 { 77 // ----------------- 78 // the closer button 79 Bitmap aCloserBitmap(SvtResId(BMP_HELP_AGENT_CLOSER)); 80 Image aCloserImage( aCloserBitmap, Color(COL_LIGHTMAGENTA) ); 81 m_pCloser = new CloserButton_Impl( this, WB_NOTABSTOP | WB_NOPOINTERFOCUS ); 82 static_cast<CloserButton_Impl*>(m_pCloser)->SetModeImage( aCloserImage ); 83 static_cast<CloserButton_Impl*>(m_pCloser)->SetClickHdl( LINK(this, HelpAgentWindow, OnButtonClicked) ); 84 m_pCloser->SetSizePixel( implOptimalButtonSize(aCloserImage) ); 85 m_pCloser->Show(); 86 m_pCloser->SetZOrder( NULL, WINDOW_ZORDER_LAST ); 87 88 // ---------------------------- 89 // calculate our preferred size 90 Bitmap aHelpAgentBitmap(SvtResId(BMP_HELP_AGENT_IMAGE)); 91 m_aPicture = Image( aHelpAgentBitmap ); 92 m_aPreferredSize = m_aPicture.GetSizePixel(); 93 m_aPreferredSize.Width() += 2; 94 m_aPreferredSize.Height() += 2; 95 96 Size aSize = GetSizePixel(); 97 Size aOutputSize = GetOutputSizePixel(); 98 m_aPreferredSize.Width() += aSize.Width() - aOutputSize.Width(); 99 m_aPreferredSize.Height() += aSize.Height() - aOutputSize.Height(); 100 101 SetPointer(Pointer(POINTER_REFHAND)); 102 AlwaysEnableInput( sal_True, sal_True ); 103 104 // unique id for the testtool 105 SetUniqueId( HID_HELPAGENT_WINDOW ); 106 } 107 108 //-------------------------------------------------------------------- 109 HelpAgentWindow::~HelpAgentWindow() 110 { 111 if (m_pCloser && m_pCloser->IsTracking()) 112 m_pCloser->EndTracking(); 113 if (m_pCloser && m_pCloser->IsMouseCaptured()) 114 m_pCloser->ReleaseMouse(); 115 116 delete m_pCloser; 117 } 118 119 //-------------------------------------------------------------------- 120 void HelpAgentWindow::Paint( const Rectangle& rRect ) 121 { 122 FloatingWindow::Paint(rRect); 123 124 Size aOutputSize( GetOutputSizePixel() ); 125 Point aPoint=Point(); 126 Rectangle aOutputRect( aPoint, aOutputSize ); 127 Rectangle aInnerRect( aOutputRect ); 128 129 // paint the background 130 SetLineColor( GetSettings().GetStyleSettings().GetFaceColor() ); 131 SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() ); 132 DrawRect( aOutputRect ); 133 134 // paint the image 135 Size aPictureSize( m_aPicture.GetSizePixel() ); 136 Point aPicturePos( 137 aOutputRect.Left() + (aInnerRect.GetWidth() - aPictureSize.Width()) / 2, 138 aOutputRect.Top() + (aInnerRect.GetHeight() - aPictureSize.Height()) / 2 ); 139 140 DrawImage( aPicturePos, m_aPicture, 0 ); 141 } 142 143 //-------------------------------------------------------------------- 144 void HelpAgentWindow::MouseButtonUp( const MouseEvent& rMEvt ) 145 { 146 FloatingWindow::MouseButtonUp(rMEvt); 147 148 if (m_pCallback) 149 m_pCallback->helpRequested(); 150 } 151 152 //-------------------------------------------------------------------- 153 Size HelpAgentWindow::implOptimalButtonSize( const Image& _rButtonImage ) 154 { 155 Size aPreferredSize = _rButtonImage.GetSizePixel(); 156 // add a small frame, needed by the button 157 aPreferredSize.Width() += 5; 158 aPreferredSize.Height() += 5; 159 return aPreferredSize; 160 } 161 162 //-------------------------------------------------------------------- 163 void HelpAgentWindow::Resize() 164 { 165 FloatingWindow::Resize(); 166 167 Size aOutputSize = GetOutputSizePixel(); 168 Size aCloserSize = m_pCloser->GetSizePixel(); 169 if (m_pCloser) 170 m_pCloser->SetPosPixel( Point(aOutputSize.Width() - aCloserSize.Width() - 3, 4) ); 171 } 172 173 //-------------------------------------------------------------------- 174 IMPL_LINK( HelpAgentWindow, OnButtonClicked, Window*, _pWhichOne ) 175 { 176 if (m_pCloser == _pWhichOne) 177 if (m_pCallback) 178 m_pCallback->closeAgent(); 179 return 0L; 180 } 181 182 //........................................................................ 183 } // namespace svt 184 //........................................................................ 185 186