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