15900e8ecSAndrew Rist /************************************************************** 2b3f70510Smseidel * 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 10b3f70510Smseidel * 115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12b3f70510Smseidel * 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. 19b3f70510Smseidel * 205900e8ecSAndrew Rist *************************************************************/ 215900e8ecSAndrew Rist 225900e8ecSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svtools.hxx" 26cdf0e10cSrcweir #include <svtools/helpagentwindow.hxx> 27cdf0e10cSrcweir #include <osl/diagnose.h> 28cdf0e10cSrcweir #include <vcl/button.hxx> 29cdf0e10cSrcweir #include <vcl/bitmap.hxx> 30cdf0e10cSrcweir #include <svtools/svtdata.hxx> 31cdf0e10cSrcweir #include <svtools/svtools.hrc> 32cdf0e10cSrcweir #include <svtools/helpid.hrc> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #define WB_AGENT_STYLE 0 35cdf0e10cSrcweir 36cdf0e10cSrcweir //........................................................................ 37cdf0e10cSrcweir namespace svt 38cdf0e10cSrcweir { 39cdf0e10cSrcweir //........................................................................ 40cdf0e10cSrcweir 41cdf0e10cSrcweir using namespace ::com::sun::star::uno; 42cdf0e10cSrcweir using namespace ::com::sun::star::lang; 43cdf0e10cSrcweir 44cdf0e10cSrcweir //==================================================================== 45cdf0e10cSrcweir //= CloserButton_Impl 46cdf0e10cSrcweir //= overload of ImageButton, because sometimes vcl doesn't call the click handler 47cdf0e10cSrcweir //==================================================================== 48cdf0e10cSrcweir //-------------------------------------------------------------------- 49cdf0e10cSrcweir class CloserButton_Impl : public ImageButton 50cdf0e10cSrcweir { 51cdf0e10cSrcweir public: CloserButton_Impl(Window * pParent,WinBits nBits)52cdf0e10cSrcweir CloserButton_Impl( Window* pParent, WinBits nBits ) : ImageButton( pParent, nBits ) {} 53cdf0e10cSrcweir 54cdf0e10cSrcweir virtual void MouseButtonUp( const MouseEvent& rMEvt ); 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir 57cdf0e10cSrcweir //-------------------------------------------------------------------- MouseButtonUp(const MouseEvent & rMEvt)58cdf0e10cSrcweir void CloserButton_Impl::MouseButtonUp( const MouseEvent& rMEvt ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir ImageButton::MouseButtonUp( rMEvt ); 61cdf0e10cSrcweir GetClickHdl().Call( this ); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir //==================================================================== 65cdf0e10cSrcweir //= HelpAgentWindow 66cdf0e10cSrcweir //==================================================================== 67cdf0e10cSrcweir //-------------------------------------------------------------------- HelpAgentWindow(Window * _pParent)68cdf0e10cSrcweir HelpAgentWindow::HelpAgentWindow( Window* _pParent ) 69cdf0e10cSrcweir :FloatingWindow( _pParent, WB_AGENT_STYLE) 70cdf0e10cSrcweir ,m_pCloser(NULL) 71cdf0e10cSrcweir ,m_pCallback(NULL) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir // ----------------- 74cdf0e10cSrcweir // the closer button 75*31869473Smseidel Bitmap aCloserBitmap(SvtResId(BMP_HELP_AGENT_CLOSER)); 76*31869473Smseidel Image aCloserImage( aCloserBitmap, Color(COL_BLACK) ); 77cdf0e10cSrcweir m_pCloser = new CloserButton_Impl( this, WB_NOTABSTOP | WB_NOPOINTERFOCUS ); 78cdf0e10cSrcweir static_cast<CloserButton_Impl*>(m_pCloser)->SetModeImage( aCloserImage ); 79cdf0e10cSrcweir static_cast<CloserButton_Impl*>(m_pCloser)->SetClickHdl( LINK(this, HelpAgentWindow, OnButtonClicked) ); 80cdf0e10cSrcweir m_pCloser->SetSizePixel( implOptimalButtonSize(aCloserImage) ); 81cdf0e10cSrcweir m_pCloser->Show(); 82cdf0e10cSrcweir m_pCloser->SetZOrder( NULL, WINDOW_ZORDER_LAST ); 83cdf0e10cSrcweir 84cdf0e10cSrcweir // ---------------------------- 85cdf0e10cSrcweir // calculate our preferred size 86cdf0e10cSrcweir Bitmap aHelpAgentBitmap(SvtResId(BMP_HELP_AGENT_IMAGE)); 87cdf0e10cSrcweir m_aPicture = Image( aHelpAgentBitmap ); 88cdf0e10cSrcweir m_aPreferredSize = m_aPicture.GetSizePixel(); 89cdf0e10cSrcweir m_aPreferredSize.Width() += 2; 90cdf0e10cSrcweir m_aPreferredSize.Height() += 2; 91cdf0e10cSrcweir 92cdf0e10cSrcweir Size aSize = GetSizePixel(); 93cdf0e10cSrcweir Size aOutputSize = GetOutputSizePixel(); 94cdf0e10cSrcweir m_aPreferredSize.Width() += aSize.Width() - aOutputSize.Width(); 95cdf0e10cSrcweir m_aPreferredSize.Height() += aSize.Height() - aOutputSize.Height(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir SetPointer(Pointer(POINTER_REFHAND)); 98b3f70510Smseidel AlwaysEnableInput( sal_True, sal_True ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir // unique id for the testtool 101cdf0e10cSrcweir SetUniqueId( HID_HELPAGENT_WINDOW ); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir //-------------------------------------------------------------------- ~HelpAgentWindow()105cdf0e10cSrcweir HelpAgentWindow::~HelpAgentWindow() 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if (m_pCloser && m_pCloser->IsTracking()) 108cdf0e10cSrcweir m_pCloser->EndTracking(); 109cdf0e10cSrcweir if (m_pCloser && m_pCloser->IsMouseCaptured()) 110cdf0e10cSrcweir m_pCloser->ReleaseMouse(); 111cdf0e10cSrcweir 112cdf0e10cSrcweir delete m_pCloser; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir //-------------------------------------------------------------------- Paint(const Rectangle & rRect)116cdf0e10cSrcweir void HelpAgentWindow::Paint( const Rectangle& rRect ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir FloatingWindow::Paint(rRect); 119cdf0e10cSrcweir 120cdf0e10cSrcweir Size aOutputSize( GetOutputSizePixel() ); 121cdf0e10cSrcweir Point aPoint=Point(); 122cdf0e10cSrcweir Rectangle aOutputRect( aPoint, aOutputSize ); 123cdf0e10cSrcweir Rectangle aInnerRect( aOutputRect ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir // paint the background 126cdf0e10cSrcweir SetLineColor( GetSettings().GetStyleSettings().GetFaceColor() ); 127cdf0e10cSrcweir SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() ); 128cdf0e10cSrcweir DrawRect( aOutputRect ); 129cdf0e10cSrcweir 130cdf0e10cSrcweir // paint the image 131cdf0e10cSrcweir Size aPictureSize( m_aPicture.GetSizePixel() ); 132cdf0e10cSrcweir Point aPicturePos( 133cdf0e10cSrcweir aOutputRect.Left() + (aInnerRect.GetWidth() - aPictureSize.Width()) / 2, 134cdf0e10cSrcweir aOutputRect.Top() + (aInnerRect.GetHeight() - aPictureSize.Height()) / 2 ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir DrawImage( aPicturePos, m_aPicture, 0 ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir //-------------------------------------------------------------------- MouseButtonUp(const MouseEvent & rMEvt)140cdf0e10cSrcweir void HelpAgentWindow::MouseButtonUp( const MouseEvent& rMEvt ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir FloatingWindow::MouseButtonUp(rMEvt); 143cdf0e10cSrcweir 144cdf0e10cSrcweir if (m_pCallback) 145cdf0e10cSrcweir m_pCallback->helpRequested(); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir //-------------------------------------------------------------------- implOptimalButtonSize(const Image & _rButtonImage)149cdf0e10cSrcweir Size HelpAgentWindow::implOptimalButtonSize( const Image& _rButtonImage ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir Size aPreferredSize = _rButtonImage.GetSizePixel(); 152cdf0e10cSrcweir // add a small frame, needed by the button 153b3f70510Smseidel aPreferredSize.Width() += 8; 154b3f70510Smseidel aPreferredSize.Height() += 8; 155cdf0e10cSrcweir return aPreferredSize; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir //-------------------------------------------------------------------- Resize()159cdf0e10cSrcweir void HelpAgentWindow::Resize() 160cdf0e10cSrcweir { 161cdf0e10cSrcweir FloatingWindow::Resize(); 162cdf0e10cSrcweir 163cdf0e10cSrcweir Size aOutputSize = GetOutputSizePixel(); 164cdf0e10cSrcweir Size aCloserSize = m_pCloser->GetSizePixel(); 165cdf0e10cSrcweir if (m_pCloser) 166b3f70510Smseidel m_pCloser->SetPosPixel( Point(aOutputSize.Width() - aCloserSize.Width() - 2, 2) ); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir //-------------------------------------------------------------------- IMPL_LINK(HelpAgentWindow,OnButtonClicked,Window *,_pWhichOne)170cdf0e10cSrcweir IMPL_LINK( HelpAgentWindow, OnButtonClicked, Window*, _pWhichOne ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir if (m_pCloser == _pWhichOne) 173cdf0e10cSrcweir if (m_pCallback) 174cdf0e10cSrcweir m_pCallback->closeAgent(); 175cdf0e10cSrcweir return 0L; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir //........................................................................ 179cdf0e10cSrcweir } // namespace svt 180cdf0e10cSrcweir //........................................................................ 181cdf0e10cSrcweir 182