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