15900e8ecSAndrew Rist /************************************************************** 2*b3f70510Smseidel * 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 10*b3f70510Smseidel * 115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*b3f70510Smseidel * 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. 19*b3f70510Smseidel * 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: 52cdf0e10cSrcweir CloserButton_Impl( Window* pParent, WinBits nBits ) : ImageButton( pParent, nBits ) {} 53cdf0e10cSrcweir 54cdf0e10cSrcweir virtual void MouseButtonUp( const MouseEvent& rMEvt ); 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir 57cdf0e10cSrcweir //-------------------------------------------------------------------- 58cdf0e10cSrcweir void CloserButton_Impl::MouseButtonUp( const MouseEvent& rMEvt ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir ImageButton::MouseButtonUp( rMEvt ); 61cdf0e10cSrcweir GetClickHdl().Call( this ); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir //==================================================================== 65cdf0e10cSrcweir //= HelpAgentWindow 66cdf0e10cSrcweir //==================================================================== 67cdf0e10cSrcweir //-------------------------------------------------------------------- 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*b3f70510Smseidel Bitmap aCloserImage(SvtResId(BMP_HELP_AGENT_CLOSER)); 76cdf0e10cSrcweir m_pCloser = new CloserButton_Impl( this, WB_NOTABSTOP | WB_NOPOINTERFOCUS ); 77cdf0e10cSrcweir static_cast<CloserButton_Impl*>(m_pCloser)->SetModeImage( aCloserImage ); 78cdf0e10cSrcweir static_cast<CloserButton_Impl*>(m_pCloser)->SetClickHdl( LINK(this, HelpAgentWindow, OnButtonClicked) ); 79cdf0e10cSrcweir m_pCloser->SetSizePixel( implOptimalButtonSize(aCloserImage) ); 80cdf0e10cSrcweir m_pCloser->Show(); 81cdf0e10cSrcweir m_pCloser->SetZOrder( NULL, WINDOW_ZORDER_LAST ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir // ---------------------------- 84cdf0e10cSrcweir // calculate our preferred size 85cdf0e10cSrcweir Bitmap aHelpAgentBitmap(SvtResId(BMP_HELP_AGENT_IMAGE)); 86cdf0e10cSrcweir m_aPicture = Image( aHelpAgentBitmap ); 87cdf0e10cSrcweir m_aPreferredSize = m_aPicture.GetSizePixel(); 88cdf0e10cSrcweir m_aPreferredSize.Width() += 2; 89cdf0e10cSrcweir m_aPreferredSize.Height() += 2; 90cdf0e10cSrcweir 91cdf0e10cSrcweir Size aSize = GetSizePixel(); 92cdf0e10cSrcweir Size aOutputSize = GetOutputSizePixel(); 93cdf0e10cSrcweir m_aPreferredSize.Width() += aSize.Width() - aOutputSize.Width(); 94cdf0e10cSrcweir m_aPreferredSize.Height() += aSize.Height() - aOutputSize.Height(); 95cdf0e10cSrcweir 96cdf0e10cSrcweir SetPointer(Pointer(POINTER_REFHAND)); 97*b3f70510Smseidel AlwaysEnableInput( sal_True, sal_True ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir // unique id for the testtool 100cdf0e10cSrcweir SetUniqueId( HID_HELPAGENT_WINDOW ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir //-------------------------------------------------------------------- 104cdf0e10cSrcweir HelpAgentWindow::~HelpAgentWindow() 105cdf0e10cSrcweir { 106cdf0e10cSrcweir if (m_pCloser && m_pCloser->IsTracking()) 107cdf0e10cSrcweir m_pCloser->EndTracking(); 108cdf0e10cSrcweir if (m_pCloser && m_pCloser->IsMouseCaptured()) 109cdf0e10cSrcweir m_pCloser->ReleaseMouse(); 110cdf0e10cSrcweir 111cdf0e10cSrcweir delete m_pCloser; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir //-------------------------------------------------------------------- 115cdf0e10cSrcweir void HelpAgentWindow::Paint( const Rectangle& rRect ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir FloatingWindow::Paint(rRect); 118cdf0e10cSrcweir 119cdf0e10cSrcweir Size aOutputSize( GetOutputSizePixel() ); 120cdf0e10cSrcweir Point aPoint=Point(); 121cdf0e10cSrcweir Rectangle aOutputRect( aPoint, aOutputSize ); 122cdf0e10cSrcweir Rectangle aInnerRect( aOutputRect ); 123cdf0e10cSrcweir 124cdf0e10cSrcweir // paint the background 125cdf0e10cSrcweir SetLineColor( GetSettings().GetStyleSettings().GetFaceColor() ); 126cdf0e10cSrcweir SetFillColor( GetSettings().GetStyleSettings().GetFaceColor() ); 127cdf0e10cSrcweir DrawRect( aOutputRect ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir // paint the image 130cdf0e10cSrcweir Size aPictureSize( m_aPicture.GetSizePixel() ); 131cdf0e10cSrcweir Point aPicturePos( 132cdf0e10cSrcweir aOutputRect.Left() + (aInnerRect.GetWidth() - aPictureSize.Width()) / 2, 133cdf0e10cSrcweir aOutputRect.Top() + (aInnerRect.GetHeight() - aPictureSize.Height()) / 2 ); 134cdf0e10cSrcweir 135cdf0e10cSrcweir DrawImage( aPicturePos, m_aPicture, 0 ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir //-------------------------------------------------------------------- 139cdf0e10cSrcweir void HelpAgentWindow::MouseButtonUp( const MouseEvent& rMEvt ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir FloatingWindow::MouseButtonUp(rMEvt); 142cdf0e10cSrcweir 143cdf0e10cSrcweir if (m_pCallback) 144cdf0e10cSrcweir m_pCallback->helpRequested(); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir //-------------------------------------------------------------------- 148cdf0e10cSrcweir Size HelpAgentWindow::implOptimalButtonSize( const Image& _rButtonImage ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir Size aPreferredSize = _rButtonImage.GetSizePixel(); 151cdf0e10cSrcweir // add a small frame, needed by the button 152*b3f70510Smseidel aPreferredSize.Width() += 8; 153*b3f70510Smseidel aPreferredSize.Height() += 8; 154cdf0e10cSrcweir return aPreferredSize; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir //-------------------------------------------------------------------- 158cdf0e10cSrcweir void HelpAgentWindow::Resize() 159cdf0e10cSrcweir { 160cdf0e10cSrcweir FloatingWindow::Resize(); 161cdf0e10cSrcweir 162cdf0e10cSrcweir Size aOutputSize = GetOutputSizePixel(); 163cdf0e10cSrcweir Size aCloserSize = m_pCloser->GetSizePixel(); 164cdf0e10cSrcweir if (m_pCloser) 165*b3f70510Smseidel m_pCloser->SetPosPixel( Point(aOutputSize.Width() - aCloserSize.Width() - 2, 2) ); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir //-------------------------------------------------------------------- 169cdf0e10cSrcweir IMPL_LINK( HelpAgentWindow, OnButtonClicked, Window*, _pWhichOne ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if (m_pCloser == _pWhichOne) 172cdf0e10cSrcweir if (m_pCallback) 173cdf0e10cSrcweir m_pCallback->closeAgent(); 174cdf0e10cSrcweir return 0L; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir //........................................................................ 178cdf0e10cSrcweir } // namespace svt 179cdf0e10cSrcweir //........................................................................ 180cdf0e10cSrcweir 181