1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include <comphelper/processfactory.hxx>
31 #include <osl/mutex.hxx>
32 #include <tools/urlobj.hxx>
33 #include <com/sun/star/frame/XDispatch.hpp>
34 #include <com/sun/star/frame/XDispatchProvider.hpp>
35 #include <com/sun/star/util/XURLTransformer.hpp>
36 #include <com/sun/star/frame/FrameSearchFlag.hpp>
38 #include <tools/debug.hxx>
39 #ifndef _SVX_SVXIDS_HRC
40 #include <svx/svxids.hrc>
42 #include <svtools/miscopt.hxx>
43 #include <svtools/imgdef.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/mnemonic.hxx>
46 #include "bibbeam.hxx"
47 #include "toolbar.hrc"
48 #include "bibresid.hxx"
51 #include "bibtools.hxx"
53 #include <vos/mutex.hxx>
55 using namespace ::rtl
;
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::beans
;
59 #define C2U(cChar) OUString::createFromAscii(cChar)
62 // Konstanten -------------------------------------------------------------
65 BibToolBarListener::BibToolBarListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
72 BibToolBarListener::~BibToolBarListener()
76 void BibToolBarListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& rEvt
)throw( ::com::sun::star::uno::RuntimeException
)
78 if(rEvt
.FeatureURL
.Complete
== aCommand
)
80 vos::OGuard
aGuard(Application::GetSolarMutex());
81 pToolBar
->EnableItem(nIndex
,rEvt
.IsEnabled
);
83 ::com::sun::star::uno::Any aState
=rEvt
.State
;
84 if(aState
.getValueType()==::getBooleanCppuType())
86 sal_Bool bChecked
= *(sal_Bool
*)aState
.getValue();
87 pToolBar
->CheckItem(nIndex
, bChecked
);
91 rtl::OUString FeatureDescriptor;
93 ::com::sun::star::uno::Any State;*/
97 rtl::OUString
BibToolBarListener::GetCommand()
102 BibTBListBoxListener::BibTBListBoxListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
103 BibToolBarListener(pTB
,aStr
,nId
)
107 BibTBListBoxListener::~BibTBListBoxListener()
111 void BibTBListBoxListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& rEvt
)throw( ::com::sun::star::uno::RuntimeException
)
113 if(rEvt
.FeatureURL
.Complete
== GetCommand())
115 vos::OGuard
aGuard(Application::GetSolarMutex());
116 pToolBar
->EnableSourceList(rEvt
.IsEnabled
);
118 Any aState
= rEvt
.State
;
119 if(aState
.getValueType() == ::getCppuType((Sequence
<rtl::OUString
>*)0))
121 pToolBar
->UpdateSourceList(sal_False
);
122 pToolBar
->ClearSourceList();
124 Sequence
<rtl::OUString
>* pStringSeq
= (Sequence
<rtl::OUString
>*)aState
.getValue();
125 const rtl::OUString
* pStringArray
= (const rtl::OUString
*)pStringSeq
->getConstArray();
127 sal_uInt32 nCount
= pStringSeq
->getLength();
129 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
131 aEntry
= String(pStringArray
[i
]);
132 pToolBar
->InsertSourceEntry(aEntry
);
134 pToolBar
->UpdateSourceList(sal_True
);
137 XubString aStr
= String(rEvt
.FeatureDescriptor
);
138 pToolBar
->SelectSourceEntry(aStr
);
142 BibTBQueryMenuListener::BibTBQueryMenuListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
143 BibToolBarListener(pTB
,aStr
,nId
)
147 BibTBQueryMenuListener::~BibTBQueryMenuListener()
151 void BibTBQueryMenuListener::statusChanged(const frame::FeatureStateEvent
& rEvt
)throw( uno::RuntimeException
)
153 if(rEvt
.FeatureURL
.Complete
== GetCommand())
155 vos::OGuard
aGuard(Application::GetSolarMutex());
156 pToolBar
->EnableSourceList(rEvt
.IsEnabled
);
158 uno::Any aState
=rEvt
.State
;
159 if(aState
.getValueType()==::getCppuType((Sequence
<rtl::OUString
>*)0))
161 pToolBar
->ClearFilterMenu();
163 Sequence
<rtl::OUString
>* pStringSeq
= (Sequence
<rtl::OUString
>*) aState
.getValue();
164 const rtl::OUString
* pStringArray
= (const rtl::OUString
*)pStringSeq
->getConstArray();
166 sal_uInt32 nCount
= pStringSeq
->getLength();
167 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
169 sal_uInt16 nID
=pToolBar
->InsertFilterItem(String(pStringArray
[i
]));
170 if(pStringArray
[i
]==rEvt
.FeatureDescriptor
)
172 // XubString aStr = rEvt.FeatureDescriptor;
173 pToolBar
->SelectFilterItem(nID
);
180 BibTBEditListener::BibTBEditListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
181 BibToolBarListener(pTB
,aStr
,nId
)
185 BibTBEditListener::~BibTBEditListener()
189 void BibTBEditListener::statusChanged(const frame::FeatureStateEvent
& rEvt
)throw( uno::RuntimeException
)
191 if(rEvt
.FeatureURL
.Complete
== GetCommand())
193 vos::OGuard
aGuard(Application::GetSolarMutex());
194 pToolBar
->EnableQuery(rEvt
.IsEnabled
);
196 uno::Any aState
=rEvt
.State
;
197 if(aState
.getValueType()==::getCppuType((const OUString
*)0))
199 String aStr
= String(*(OUString
*) aState
.getValue());
200 pToolBar
->SetQueryString(aStr
);
205 SV_IMPL_PTRARR( BibToolBarListenerArr
, BibToolBarListenerPtr
);
207 BibToolBar::BibToolBar(Window
* pParent
, Link aLink
, WinBits nStyle
):
208 ToolBox(pParent
,BibResId(RID_BIB_TOOLBAR
)),
209 aImgLst(BibResId( RID_TOOLBAR_IMGLIST
)),
210 aImgLstHC(BibResId(RID_TOOLBAR_IMGLIST_HC
)),
211 aBigImgLst(BibResId( RID_TOOLBAR_BIGIMGLIST
)),
212 aBigImgLstHC(BibResId( RID_TOOLBAR_BIGIMGLIST_HC
)),
213 aFtSource(this,WB_VCENTER
),
214 aLBSource(this,WB_DROPDOWN
),
215 aFtQuery(this,WB_VCENTER
),
219 aLayoutManager( aLink
),
220 nSymbolsSize( SFX_SYMBOLS_SIZE_SMALL
),
223 SvtMiscOptions aSvtMiscOptions
;
224 nSymbolsSize
= aSvtMiscOptions
.GetCurrentSymbolsSize();
225 nOutStyle
= aSvtMiscOptions
.GetToolboxStyle();
228 SetStyle(GetStyle()|nStyle
);
229 SetOutStyle(TOOLBOX_STYLE_FLAT
);
230 Size aSize
=GetSizePixel();
231 Size
a2Size(GetOutputSizePixel());
233 aLBSource
.SetSizePixel(a2Size
);
234 aLBSource
.SetDropDownLineCount(9);
236 aLBSource
.SetSelectHdl(LINK( this, BibToolBar
, SelHdl
));
238 SvtMiscOptions().AddListenerLink( LINK( this, BibToolBar
, OptionsChanged_Impl
) );
239 Application::AddEventListener( LINK( this, BibToolBar
, SettingsChanged_Impl
) );
241 aTimer
.SetTimeoutHdl(LINK( this, BibToolBar
, SendSelHdl
));
242 aTimer
.SetTimeout(400);
244 SetDropdownClickHdl( LINK( this, BibToolBar
, MenuHdl
));
246 aEdQuery
.SetSizePixel(aLBSource
.GetSizePixel());
249 XubString aStr
=GetItemText(TBC_FT_SOURCE
);
250 Rectangle aRect
=GetItemRect(TBC_FT_SOURCE
);
251 aFtSource
.SetText(aStr
);
252 aFtSource
.SetSizePixel(aRect
.GetSize());
253 aFtSource
.SetBackground(Wallpaper( COL_TRANSPARENT
));
255 aStr
=GetItemText(TBC_FT_QUERY
);
256 aRect
=GetItemRect(TBC_FT_QUERY
);
257 aFtQuery
.SetText(aStr
);
258 aFtQuery
.SetSizePixel(aRect
.GetSize());
259 aFtQuery
.SetBackground(Wallpaper( COL_TRANSPARENT
));
261 SetItemWindow(TBC_FT_SOURCE
,&aFtSource
);
262 SetItemWindow(TBC_LB_SOURCE
,&aLBSource
);
263 SetItemWindow(TBC_FT_QUERY
,&aFtQuery
);
264 SetItemWindow(TBC_ED_QUERY
,&aEdQuery
);
266 ::bib::AddToTaskPaneList( this );
269 BibToolBar::~BibToolBar()
271 SvtMiscOptions().RemoveListenerLink( LINK( this, BibToolBar
, OptionsChanged_Impl
) );
272 Application::RemoveEventListener( LINK( this, BibToolBar
, SettingsChanged_Impl
) );
273 ::bib::RemoveFromTaskPaneList( this );
276 void BibToolBar::InitListener()
278 sal_uInt16 nCount
=GetItemCount();
280 uno::Reference
< lang::XMultiServiceFactory
> xMgr
= comphelper::getProcessServiceFactory();
281 uno::Reference
< frame::XDispatch
> xDisp(xController
,UNO_QUERY
);
283 uno::Reference
< util::XURLTransformer
> xTrans ( xMgr
->createInstance( C2U("com.sun.star.util.URLTransformer") ), UNO_QUERY
);
287 aQueryURL
.Complete
= C2U(".uno:Bib/MenuFilter");
288 xTrans
->parseStrict( aQueryURL
);
289 BibToolBarListener
* pQuery
=new BibTBQueryMenuListener(this,aQueryURL
.Complete
,TBC_BT_AUTOFILTER
);
290 xDisp
->addStatusListener(uno::Reference
< frame::XStatusListener
> (pQuery
),aQueryURL
);
292 for(sal_uInt16 nPos
=0;nPos
<nCount
;nPos
++)
294 sal_uInt16 nId
=GetItemId(nPos
);
295 if(!nId
|| nId
==TBC_FT_SOURCE
|| nId
==TBC_FT_QUERY
)
299 aURL
.Complete
= GetItemCommand(nId
);
300 if(!aURL
.Complete
.getLength())
303 xTrans
->parseStrict( aURL
);
305 BibToolBarListener
* pListener
=NULL
;
306 if(nId
==TBC_LB_SOURCE
)
308 pListener
=new BibTBListBoxListener(this,aURL
.Complete
,nId
);
310 else if(nId
==TBC_ED_QUERY
)
312 pListener
=new BibTBEditListener(this,aURL
.Complete
,nId
);
316 pListener
=new BibToolBarListener(this,aURL
.Complete
,nId
);
319 BibToolBarListenerPtr pxInsert
= new Reference
<frame::XStatusListener
>;
320 (*pxInsert
) = pListener
;
321 aListenerArr
.Insert( pxInsert
, aListenerArr
.Count() );
322 xDisp
->addStatusListener(uno::Reference
< frame::XStatusListener
> (pListener
),aURL
);
327 void BibToolBar::SetXController(const uno::Reference
< frame::XController
> & xCtr
)
334 void BibToolBar::Select()
336 sal_uInt16 nId
=GetCurItemId();
338 if(nId
!=TBC_BT_AUTOFILTER
)
340 SendDispatch(nId
,Sequence
<PropertyValue
>() );
344 Sequence
<PropertyValue
> aPropVal(2);
345 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
346 pPropertyVal
[0].Name
=C2U("QueryText");
347 rtl::OUString aSelection
= aEdQuery
.GetText();
348 pPropertyVal
[0].Value
<<= aSelection
;
350 pPropertyVal
[1].Name
=C2U("QueryField");
351 pPropertyVal
[1].Value
<<= aQueryField
;
352 SendDispatch(nId
,aPropVal
);
356 void BibToolBar::SendDispatch(sal_uInt16 nId
, const Sequence
< PropertyValue
>& rArgs
)
358 rtl::OUString aCommand
= GetItemCommand(nId
);
360 uno::Reference
< frame::XDispatchProvider
> xDSP( xController
, UNO_QUERY
);
362 if( xDSP
.is() && aCommand
.getLength())
364 uno::Reference
< lang::XMultiServiceFactory
> xMgr
= comphelper::getProcessServiceFactory();
366 uno::Reference
< util::XURLTransformer
> xTrans ( xMgr
->createInstance( C2U("com.sun.star.util.URLTransformer") ), UNO_QUERY
);
371 aURL
.Complete
= aCommand
;
373 xTrans
->parseStrict( aURL
);
375 uno::Reference
< frame::XDispatch
> xDisp
= xDSP
->queryDispatch( aURL
, rtl::OUString(), frame::FrameSearchFlag::SELF
);
378 xDisp
->dispatch( aURL
, rArgs
);
384 void BibToolBar::Click()
386 sal_uInt16 nId
=GetCurItemId();
388 if(nId
== TBC_BT_COL_ASSIGN
)
391 pDatMan
->CreateMappingDialog(GetParent());
392 CheckItem( nId
, FALSE
);
394 else if(nId
== TBC_BT_CHANGESOURCE
)
398 OUString sNew
= pDatMan
->CreateDBChangeDialog(GetParent());
400 pDatMan
->setActiveDataSource(sNew
);
402 CheckItem( nId
, FALSE
);
406 void BibToolBar::ClearFilterMenu()
411 sal_uInt16
BibToolBar::InsertFilterItem(const XubString
& aMenuEntry
)
414 aPopupMenu
.InsertItem(nMenuId
,aMenuEntry
);
418 void BibToolBar::SelectFilterItem(sal_uInt16 nId
)
420 aPopupMenu
.CheckItem(nId
);
422 aQueryField
= MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu
.GetItemText(nId
) );
425 void BibToolBar::EnableSourceList(sal_Bool bFlag
)
427 aFtSource
.Enable(bFlag
);
428 aLBSource
.Enable(bFlag
);
431 void BibToolBar::ClearSourceList()
436 void BibToolBar::UpdateSourceList(sal_Bool bFlag
)
438 aLBSource
.SetUpdateMode(bFlag
);
441 void BibToolBar::InsertSourceEntry(const XubString
& aEntry
, sal_uInt16 nPos
)
443 aLBSource
.InsertEntry(aEntry
, nPos
);
446 void BibToolBar::SelectSourceEntry(const XubString
& aStr
)
448 aLBSource
.SelectEntry(aStr
);
451 void BibToolBar::EnableQuery(sal_Bool bFlag
)
453 aFtQuery
.Enable(bFlag
);
454 aEdQuery
.Enable(bFlag
);
457 void BibToolBar::SetQueryString(const XubString
& aStr
)
459 aEdQuery
.SetText(aStr
);
463 long BibToolBar::PreNotify( NotifyEvent
& rNEvt
)
465 long nResult
=sal_True
;
467 sal_uInt16 nSwitch
=rNEvt
.GetType();
468 if(aEdQuery
.HasFocus() && nSwitch
==EVENT_KEYINPUT
)// || nSwitch==EVENT_KEYUP)
470 const KeyCode
& aKeyCode
=rNEvt
.GetKeyEvent()->GetKeyCode();
471 sal_uInt16 nKey
= aKeyCode
.GetCode();
472 if(nKey
== KEY_RETURN
)
474 Sequence
<PropertyValue
> aPropVal(2);
475 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
476 pPropertyVal
[0].Name
= C2U("QueryText");
477 rtl::OUString aSelection
= aEdQuery
.GetText();
478 pPropertyVal
[0].Value
<<= aSelection
;
479 pPropertyVal
[1].Name
=C2U("QueryField");
480 pPropertyVal
[1].Value
<<= aQueryField
;
481 SendDispatch(TBC_BT_AUTOFILTER
,aPropVal
);
487 nResult
=ToolBox::PreNotify(rNEvt
);
492 IMPL_LINK( BibToolBar
, SelHdl
, ListBox
*, /*pLb*/ )
498 IMPL_LINK( BibToolBar
, SendSelHdl
, Timer
*,/*pT*/)
500 Sequence
<PropertyValue
> aPropVal(1);
501 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
502 pPropertyVal
[0].Name
= C2U("DataSourceName");
503 String
aEntry( MnemonicGenerator::EraseAllMnemonicChars( aLBSource
.GetSelectEntry() ) );
504 rtl::OUString aSelection
= aEntry
;
505 pPropertyVal
[0].Value
<<= aSelection
;
506 SendDispatch(TBC_LB_SOURCE
,aPropVal
);
510 //-----------------------------------------------------------------------------
511 IMPL_LINK( BibToolBar
, MenuHdl
, ToolBox
*, /*pToolbox*/)
513 sal_uInt16 nId
=GetCurItemId();
514 if(nId
==TBC_BT_AUTOFILTER
)
516 EndSelection(); // vor SetDropMode (SetDropMode ruft SetItemImage)
518 SetItemDown(TBC_BT_AUTOFILTER
,sal_True
);
519 nId
= aPopupMenu
.Execute(this, GetItemRect(TBC_BT_AUTOFILTER
));
524 aPopupMenu
.CheckItem(nSelMenuItem
,sal_False
);
525 aPopupMenu
.CheckItem(nId
);
527 aQueryField
= MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu
.GetItemText(nId
) );
528 Sequence
<PropertyValue
> aPropVal(2);
529 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
530 pPropertyVal
[0].Name
= C2U("QueryText");
531 rtl::OUString aSelection
= aEdQuery
.GetText();
532 pPropertyVal
[0].Value
<<= aSelection
;
533 pPropertyVal
[1].Name
=C2U("QueryField");
534 pPropertyVal
[1].Value
<<= aQueryField
;
535 SendDispatch(TBC_BT_AUTOFILTER
,aPropVal
);
539 MouseEvent
aLeave( aPoint
, 0, MOUSE_LEAVEWINDOW
| MOUSE_SYNTHETIC
);
541 SetItemDown(TBC_BT_AUTOFILTER
,sal_False
);
547 //-----------------------------------------------------------------------------
548 void BibToolBar::statusChanged(const frame::FeatureStateEvent
& rEvent
)
549 throw( uno::RuntimeException
)
551 for(sal_uInt16 i
= 0; i
< aListenerArr
.Count(); i
++)
553 BibToolBarListenerPtr pListener
= aListenerArr
.GetObject(i
);
554 (*pListener
)->statusChanged(rEvent
);
557 /* -----------------------------07.05.2002 15:08------------------------------
559 ---------------------------------------------------------------------------*/
560 void BibToolBar::DataChanged( const DataChangedEvent
& rDCEvt
)
562 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
563 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
565 ToolBox::DataChanged( rDCEvt
);
567 /* -----------------------------07.05.2002 15:09------------------------------
568 ---------------------------------------------------------------------------*/
570 IMPL_LINK( BibToolBar
, OptionsChanged_Impl
, void*, /*pVoid*/ )
572 sal_Bool bRebuildToolBar
= sal_False
;
573 sal_Int16 eSymbolsSize
= SvtMiscOptions().GetCurrentSymbolsSize();
574 if ( nSymbolsSize
!= eSymbolsSize
)
576 nSymbolsSize
= eSymbolsSize
;
577 bRebuildToolBar
= sal_True
;
579 else if ( nOutStyle
!= SvtMiscOptions().GetToolboxStyle() )
581 nOutStyle
= SvtMiscOptions().GetToolboxStyle();
582 SetOutStyle( nOutStyle
);
583 bRebuildToolBar
= sal_True
;
586 if ( bRebuildToolBar
)
592 //-----------------------------------------------------------------------------
594 IMPL_LINK( BibToolBar
, SettingsChanged_Impl
, void*, /*pVoid*/ )
596 // Check if toolbar button size have changed and we have to use system settings
597 sal_Int16 eSymbolsSize
= SvtMiscOptions().GetCurrentSymbolsSize();
598 if ( eSymbolsSize
!= nSymbolsSize
)
600 nSymbolsSize
= eSymbolsSize
;
607 //-----------------------------------------------------------------------------
608 void BibToolBar::RebuildToolbar()
611 // We have to call parent asynchronously as SetSize works also asynchronously!
612 Application::PostUserEvent( aLayoutManager
, 0 );
615 //-----------------------------------------------------------------------------
617 void BibToolBar::ApplyImageList()
619 ImageList
& rList
= ( nSymbolsSize
== SFX_SYMBOLS_SIZE_SMALL
) ?
620 ( GetSettings().GetStyleSettings().GetHighContrastMode() ? aImgLstHC
: aImgLst
) :
621 ( GetSettings().GetStyleSettings().GetHighContrastMode() ? aBigImgLstHC
: aBigImgLst
);
623 SetItemImage(TBC_BT_AUTOFILTER
, rList
.GetImage(SID_FM_AUTOFILTER
));
624 SetItemImage(TBC_BT_FILTERCRIT
, rList
.GetImage(SID_FM_FILTERCRIT
));
625 SetItemImage(TBC_BT_REMOVEFILTER
, rList
.GetImage(SID_FM_REMOVE_FILTER_SORT
));
629 void BibToolBar::AdjustToolBox()
631 Size aOldSize
= GetSizePixel();
632 Size aSize
= CalcWindowSizePixel();
633 if ( !aSize
.Width() )
634 aSize
.Width() = aOldSize
.Width();
635 else if ( !aSize
.Height() )
636 aSize
.Height() = aOldSize
.Height();
638 Size aTbSize
= GetSizePixel();
640 (aSize
.Width() && aSize
.Width() != aTbSize
.Width()) ||
641 (aSize
.Height() && aSize
.Height() != aTbSize
.Height())
644 SetPosSizePixel( GetPosPixel(), aSize
);