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