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_svx.hxx"
26 
27 #include "svx/formatpaintbrushctrl.hxx"
28 
29 // header for class SfxBoolItem
30 #include <svl/eitem.hxx>
31 
32 // header for define SFX_APP
33 #include <sfx2/app.hxx>
34 
35 // header for class ToolBox
36 #include <vcl/toolbox.hxx>
37 
38 //.............................................................................
39 namespace svx
40 {
41 //.............................................................................
42 
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 
46 SFX_IMPL_TOOLBOX_CONTROL( FormatPaintBrushToolBoxControl, SfxBoolItem );
47 
FormatPaintBrushToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)48 FormatPaintBrushToolBoxControl::FormatPaintBrushToolBoxControl(	sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
49     : SfxToolBoxControl( nSlotId, nId, rTbx )
50     , m_bPersistentCopy(false)
51     , m_aDoubleClickTimer()
52 {
53     sal_uIntPtr nDblClkTime = rTbx.GetSettings().GetMouseSettings().GetDoubleClickTime();
54 
55     m_aDoubleClickTimer.SetTimeoutHdl( LINK(this, FormatPaintBrushToolBoxControl, WaitDoubleClickHdl) );
56     m_aDoubleClickTimer.SetTimeout(nDblClkTime);
57 }
58 
59 // -----------------------------------------------------------------------
60 
~FormatPaintBrushToolBoxControl()61 FormatPaintBrushToolBoxControl::~FormatPaintBrushToolBoxControl()
62 {
63     m_aDoubleClickTimer.Stop();
64 }
65 
66 // -----------------------------------------------------------------------
impl_executePaintBrush()67 void FormatPaintBrushToolBoxControl::impl_executePaintBrush()
68 {
69     Sequence< PropertyValue > aArgs( 1 );
70     aArgs[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PersistentCopy" ));
71     aArgs[0].Value = makeAny( static_cast<sal_Bool>(m_bPersistentCopy) );
72     Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FormatPaintbrush" ))
73         , aArgs );
74 }
75 
76 // -----------------------------------------------------------------------
DoubleClick()77 void FormatPaintBrushToolBoxControl::DoubleClick()
78 {
79     m_aDoubleClickTimer.Stop();
80 
81     m_bPersistentCopy = true;
82     this->impl_executePaintBrush();
83 }
84 
85 // -----------------------------------------------------------------------
Click()86 void FormatPaintBrushToolBoxControl::Click()
87 {
88     m_bPersistentCopy = false;
89     m_aDoubleClickTimer.Start();
90 }
91 
92 // -----------------------------------------------------------------------
IMPL_LINK(FormatPaintBrushToolBoxControl,WaitDoubleClickHdl,void *,EMPTYARG)93 IMPL_LINK(FormatPaintBrushToolBoxControl, WaitDoubleClickHdl, void*, EMPTYARG )
94 {
95     //there was no second click during waiting
96     this->impl_executePaintBrush();
97     return 0;
98 }
99 
100 // -----------------------------------------------------------------------
Select(sal_Bool)101 void FormatPaintBrushToolBoxControl::Select( sal_Bool )
102 {
103 }
104 
105 // -----------------------------------------------------------------------
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)106 void FormatPaintBrushToolBoxControl::StateChanged( sal_uInt16 nSID, SfxItemState eState,
107                 const SfxPoolItem* pState )
108 {
109     if( ( eState & SFX_ITEM_SET ) == 0 )
110         m_bPersistentCopy = false;
111     SfxToolBoxControl::StateChanged( nSID, eState, pState );
112 }
113 
114 //.............................................................................
115 } //namespace svx
116 //.............................................................................
117