1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <comphelper/processfactory.hxx>
30 #include <com/sun/star/frame/XDispatch.hpp>
31 #include <com/sun/star/frame/XDispatchProvider.hpp>
32 #include <com/sun/star/util/XURLTransformer.hpp>
33 #include <com/sun/star/frame/FrameSearchFlag.hpp>
35 #include <svx/svxids.hrc>
36 #include <svtools/miscopt.hxx>
37 #include <svtools/imgdef.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/mnemonic.hxx>
40 #include "bibbeam.hxx"
41 #include "toolbar.hrc"
42 #include "bibresid.hxx"
44 #include "bibtools.hxx"
45 #include <osl/mutex.hxx>
47 using namespace ::rtl
;
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::beans
;
51 #define C2U(cChar) OUString::createFromAscii(cChar)
54 // Konstanten -------------------------------------------------------------
57 BibToolBarListener::BibToolBarListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
64 BibToolBarListener::~BibToolBarListener()
68 void BibToolBarListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& rEvt
)throw( ::com::sun::star::uno::RuntimeException
)
70 if(rEvt
.FeatureURL
.Complete
== aCommand
)
72 SolarMutexGuard aGuard
;
73 pToolBar
->EnableItem(nIndex
,rEvt
.IsEnabled
);
75 ::com::sun::star::uno::Any aState
=rEvt
.State
;
76 if(aState
.getValueType()==::getBooleanCppuType())
78 sal_Bool bChecked
= *(sal_Bool
*)aState
.getValue();
79 pToolBar
->CheckItem(nIndex
, bChecked
);
85 rtl::OUString
BibToolBarListener::GetCommand() const
90 BibTBListBoxListener::BibTBListBoxListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
91 BibToolBarListener(pTB
,aStr
,nId
)
95 BibTBListBoxListener::~BibTBListBoxListener()
99 void BibTBListBoxListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& rEvt
)throw( ::com::sun::star::uno::RuntimeException
)
101 if(rEvt
.FeatureURL
.Complete
== GetCommand())
103 SolarMutexGuard aGuard
;
104 pToolBar
->EnableSourceList(rEvt
.IsEnabled
);
106 Any aState
= rEvt
.State
;
107 if(aState
.getValueType() == ::getCppuType((Sequence
<rtl::OUString
>*)0))
109 pToolBar
->UpdateSourceList(sal_False
);
110 pToolBar
->ClearSourceList();
112 Sequence
<rtl::OUString
>* pStringSeq
= (Sequence
<rtl::OUString
>*)aState
.getValue();
113 const rtl::OUString
* pStringArray
= (const rtl::OUString
*)pStringSeq
->getConstArray();
115 sal_uInt32 nCount
= pStringSeq
->getLength();
117 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
119 aEntry
= String(pStringArray
[i
]);
120 pToolBar
->InsertSourceEntry(aEntry
);
122 pToolBar
->UpdateSourceList(sal_True
);
125 XubString aStr
= String(rEvt
.FeatureDescriptor
);
126 pToolBar
->SelectSourceEntry(aStr
);
130 BibTBQueryMenuListener::BibTBQueryMenuListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
131 BibToolBarListener(pTB
,aStr
,nId
)
135 BibTBQueryMenuListener::~BibTBQueryMenuListener()
139 void BibTBQueryMenuListener::statusChanged(const frame::FeatureStateEvent
& rEvt
)throw( uno::RuntimeException
)
141 if(rEvt
.FeatureURL
.Complete
== GetCommand())
143 SolarMutexGuard aGuard
;
144 pToolBar
->EnableSourceList(rEvt
.IsEnabled
);
146 uno::Any aState
=rEvt
.State
;
147 if(aState
.getValueType()==::getCppuType((Sequence
<rtl::OUString
>*)0))
149 pToolBar
->ClearFilterMenu();
151 Sequence
<rtl::OUString
>* pStringSeq
= (Sequence
<rtl::OUString
>*) aState
.getValue();
152 const rtl::OUString
* pStringArray
= (const rtl::OUString
*)pStringSeq
->getConstArray();
154 sal_uInt32 nCount
= pStringSeq
->getLength();
155 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
157 sal_uInt16 nID
=pToolBar
->InsertFilterItem(String(pStringArray
[i
]));
158 if(pStringArray
[i
]==rEvt
.FeatureDescriptor
)
160 pToolBar
->SelectFilterItem(nID
);
167 BibTBEditListener::BibTBEditListener(BibToolBar
*pTB
,rtl::OUString aStr
,sal_uInt16 nId
):
168 BibToolBarListener(pTB
,aStr
,nId
)
172 BibTBEditListener::~BibTBEditListener()
176 void BibTBEditListener::statusChanged(const frame::FeatureStateEvent
& rEvt
)throw( uno::RuntimeException
)
178 if(rEvt
.FeatureURL
.Complete
== GetCommand())
180 SolarMutexGuard aGuard
;
181 pToolBar
->EnableQuery(rEvt
.IsEnabled
);
183 uno::Any aState
=rEvt
.State
;
184 if(aState
.getValueType()==::getCppuType((const OUString
*)0))
186 String aStr
= String(*(OUString
*) aState
.getValue());
187 pToolBar
->SetQueryString(aStr
);
192 SV_IMPL_PTRARR( BibToolBarListenerArr
, BibToolBarListenerPtr
);
194 BibToolBar::BibToolBar(Window
* pParent
, Link aLink
, WinBits nStyle
):
195 ToolBox(pParent
,BibResId(RID_BIB_TOOLBAR
)),
196 aImgLst(BibResId( RID_TOOLBAR_IMGLIST
)),
197 aBigImgLst(BibResId( RID_TOOLBAR_BIGIMGLIST
)),
198 aFtSource(this,WB_VCENTER
),
199 aLBSource(this,WB_DROPDOWN
),
200 aFtQuery(this,WB_VCENTER
),
204 aLayoutManager( aLink
),
205 nSymbolsSize( SFX_SYMBOLS_SIZE_SMALL
),
208 SvtMiscOptions aSvtMiscOptions
;
209 nSymbolsSize
= aSvtMiscOptions
.GetCurrentSymbolsSize();
210 nOutStyle
= aSvtMiscOptions
.GetToolboxStyle();
213 SetStyle(GetStyle()|nStyle
);
214 SetOutStyle(TOOLBOX_STYLE_FLAT
);
215 Size
a2Size(GetOutputSizePixel());
217 aLBSource
.SetSizePixel(a2Size
);
218 aLBSource
.SetDropDownLineCount(9);
220 aLBSource
.SetSelectHdl(LINK( this, BibToolBar
, SelHdl
));
222 SvtMiscOptions().AddListenerLink( LINK( this, BibToolBar
, OptionsChanged_Impl
) );
223 Application::AddEventListener( LINK( this, BibToolBar
, SettingsChanged_Impl
) );
225 aTimer
.SetTimeoutHdl(LINK( this, BibToolBar
, SendSelHdl
));
226 aTimer
.SetTimeout(400);
228 SetDropdownClickHdl( LINK( this, BibToolBar
, MenuHdl
));
230 aEdQuery
.SetSizePixel(aLBSource
.GetSizePixel());
233 XubString aStr
=GetItemText(TBC_FT_SOURCE
);
234 Rectangle aRect
=GetItemRect(TBC_FT_SOURCE
);
235 aFtSource
.SetText(aStr
);
236 aFtSource
.SetSizePixel(aRect
.GetSize());
237 aFtSource
.SetBackground(Wallpaper( COL_TRANSPARENT
));
239 aStr
=GetItemText(TBC_FT_QUERY
);
240 aRect
=GetItemRect(TBC_FT_QUERY
);
241 aFtQuery
.SetText(aStr
);
242 aFtQuery
.SetSizePixel(aRect
.GetSize());
243 aFtQuery
.SetBackground(Wallpaper( COL_TRANSPARENT
));
245 SetItemWindow(TBC_FT_SOURCE
,&aFtSource
);
246 SetItemWindow(TBC_LB_SOURCE
,&aLBSource
);
247 SetItemWindow(TBC_FT_QUERY
,&aFtQuery
);
248 SetItemWindow(TBC_ED_QUERY
,&aEdQuery
);
250 ::bib::AddToTaskPaneList( this );
253 BibToolBar::~BibToolBar()
255 SvtMiscOptions().RemoveListenerLink( LINK( this, BibToolBar
, OptionsChanged_Impl
) );
256 Application::RemoveEventListener( LINK( this, BibToolBar
, SettingsChanged_Impl
) );
257 ::bib::RemoveFromTaskPaneList( this );
260 void BibToolBar::InitListener()
262 sal_uInt16 nCount
=GetItemCount();
264 uno::Reference
< lang::XMultiServiceFactory
> xMgr
= comphelper::getProcessServiceFactory();
265 uno::Reference
< frame::XDispatch
> xDisp(xController
,UNO_QUERY
);
267 uno::Reference
< util::XURLTransformer
> xTrans ( xMgr
->createInstance( C2U("com.sun.star.util.URLTransformer") ), UNO_QUERY
);
271 aQueryURL
.Complete
= C2U(".uno:Bib/MenuFilter");
272 xTrans
->parseStrict( aQueryURL
);
273 BibToolBarListener
* pQuery
=new BibTBQueryMenuListener(this,aQueryURL
.Complete
,TBC_BT_AUTOFILTER
);
274 xDisp
->addStatusListener(uno::Reference
< frame::XStatusListener
> (pQuery
),aQueryURL
);
276 for(sal_uInt16 nPos
=0;nPos
<nCount
;nPos
++)
278 sal_uInt16 nId
=GetItemId(nPos
);
279 if(!nId
|| nId
==TBC_FT_SOURCE
|| nId
==TBC_FT_QUERY
)
283 aURL
.Complete
= GetItemCommand(nId
);
284 if(aURL
.Complete
.isEmpty())
287 xTrans
->parseStrict( aURL
);
289 BibToolBarListener
* pListener
=NULL
;
290 if(nId
==TBC_LB_SOURCE
)
292 pListener
=new BibTBListBoxListener(this,aURL
.Complete
,nId
);
294 else if(nId
==TBC_ED_QUERY
)
296 pListener
=new BibTBEditListener(this,aURL
.Complete
,nId
);
300 pListener
=new BibToolBarListener(this,aURL
.Complete
,nId
);
303 BibToolBarListenerPtr pxInsert
= new Reference
<frame::XStatusListener
>;
304 (*pxInsert
) = pListener
;
305 aListenerArr
.Insert( pxInsert
, aListenerArr
.Count() );
306 xDisp
->addStatusListener(uno::Reference
< frame::XStatusListener
> (pListener
),aURL
);
311 void BibToolBar::SetXController(const uno::Reference
< frame::XController
> & xCtr
)
318 void BibToolBar::Select()
320 sal_uInt16 nId
=GetCurItemId();
322 if(nId
!=TBC_BT_AUTOFILTER
)
324 SendDispatch(nId
,Sequence
<PropertyValue
>() );
328 Sequence
<PropertyValue
> aPropVal(2);
329 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
330 pPropertyVal
[0].Name
=C2U("QueryText");
331 rtl::OUString aSelection
= aEdQuery
.GetText();
332 pPropertyVal
[0].Value
<<= aSelection
;
334 pPropertyVal
[1].Name
=C2U("QueryField");
335 pPropertyVal
[1].Value
<<= aQueryField
;
336 SendDispatch(nId
,aPropVal
);
340 void BibToolBar::SendDispatch(sal_uInt16 nId
, const Sequence
< PropertyValue
>& rArgs
)
342 rtl::OUString aCommand
= GetItemCommand(nId
);
344 uno::Reference
< frame::XDispatchProvider
> xDSP( xController
, UNO_QUERY
);
346 if( xDSP
.is() && !aCommand
.isEmpty())
348 uno::Reference
< lang::XMultiServiceFactory
> xMgr
= comphelper::getProcessServiceFactory();
350 uno::Reference
< util::XURLTransformer
> xTrans ( xMgr
->createInstance( C2U("com.sun.star.util.URLTransformer") ), UNO_QUERY
);
355 aURL
.Complete
= aCommand
;
357 xTrans
->parseStrict( aURL
);
359 uno::Reference
< frame::XDispatch
> xDisp
= xDSP
->queryDispatch( aURL
, rtl::OUString(), frame::FrameSearchFlag::SELF
);
362 xDisp
->dispatch( aURL
, rArgs
);
368 void BibToolBar::Click()
370 sal_uInt16 nId
=GetCurItemId();
372 if(nId
== TBC_BT_COL_ASSIGN
)
375 pDatMan
->CreateMappingDialog(GetParent());
376 CheckItem( nId
, sal_False
);
378 else if(nId
== TBC_BT_CHANGESOURCE
)
382 OUString sNew
= pDatMan
->CreateDBChangeDialog(GetParent());
384 pDatMan
->setActiveDataSource(sNew
);
386 CheckItem( nId
, sal_False
);
390 void BibToolBar::ClearFilterMenu()
395 sal_uInt16
BibToolBar::InsertFilterItem(const XubString
& aMenuEntry
)
398 aPopupMenu
.InsertItem(nMenuId
,aMenuEntry
);
402 void BibToolBar::SelectFilterItem(sal_uInt16 nId
)
404 aPopupMenu
.CheckItem(nId
);
406 aQueryField
= MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu
.GetItemText(nId
) );
409 void BibToolBar::EnableSourceList(sal_Bool bFlag
)
411 aFtSource
.Enable(bFlag
);
412 aLBSource
.Enable(bFlag
);
415 void BibToolBar::ClearSourceList()
420 void BibToolBar::UpdateSourceList(sal_Bool bFlag
)
422 aLBSource
.SetUpdateMode(bFlag
);
425 void BibToolBar::InsertSourceEntry(const XubString
& aEntry
, sal_uInt16 nPos
)
427 aLBSource
.InsertEntry(aEntry
, nPos
);
430 void BibToolBar::SelectSourceEntry(const XubString
& aStr
)
432 aLBSource
.SelectEntry(aStr
);
435 void BibToolBar::EnableQuery(sal_Bool bFlag
)
437 aFtQuery
.Enable(bFlag
);
438 aEdQuery
.Enable(bFlag
);
441 void BibToolBar::SetQueryString(const XubString
& aStr
)
443 aEdQuery
.SetText(aStr
);
447 long BibToolBar::PreNotify( NotifyEvent
& rNEvt
)
449 long nResult
=sal_True
;
451 sal_uInt16 nSwitch
=rNEvt
.GetType();
452 if(aEdQuery
.HasFocus() && nSwitch
==EVENT_KEYINPUT
)
454 const KeyCode
& aKeyCode
=rNEvt
.GetKeyEvent()->GetKeyCode();
455 sal_uInt16 nKey
= aKeyCode
.GetCode();
456 if(nKey
== KEY_RETURN
)
458 Sequence
<PropertyValue
> aPropVal(2);
459 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
460 pPropertyVal
[0].Name
= C2U("QueryText");
461 rtl::OUString aSelection
= aEdQuery
.GetText();
462 pPropertyVal
[0].Value
<<= aSelection
;
463 pPropertyVal
[1].Name
=C2U("QueryField");
464 pPropertyVal
[1].Value
<<= aQueryField
;
465 SendDispatch(TBC_BT_AUTOFILTER
,aPropVal
);
471 nResult
=ToolBox::PreNotify(rNEvt
);
476 IMPL_LINK( BibToolBar
, SelHdl
, ListBox
*, /*pLb*/ )
482 IMPL_LINK( BibToolBar
, SendSelHdl
, Timer
*,/*pT*/)
484 Sequence
<PropertyValue
> aPropVal(1);
485 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
486 pPropertyVal
[0].Name
= C2U("DataSourceName");
487 String
aEntry( MnemonicGenerator::EraseAllMnemonicChars( aLBSource
.GetSelectEntry() ) );
488 rtl::OUString aSelection
= aEntry
;
489 pPropertyVal
[0].Value
<<= aSelection
;
490 SendDispatch(TBC_LB_SOURCE
,aPropVal
);
494 //-----------------------------------------------------------------------------
495 IMPL_LINK( BibToolBar
, MenuHdl
, ToolBox
*, /*pToolbox*/)
497 sal_uInt16 nId
=GetCurItemId();
498 if(nId
==TBC_BT_AUTOFILTER
)
500 EndSelection(); // vor SetDropMode (SetDropMode ruft SetItemImage)
502 SetItemDown(TBC_BT_AUTOFILTER
,sal_True
);
503 nId
= aPopupMenu
.Execute(this, GetItemRect(TBC_BT_AUTOFILTER
));
508 aPopupMenu
.CheckItem(nSelMenuItem
,sal_False
);
509 aPopupMenu
.CheckItem(nId
);
511 aQueryField
= MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu
.GetItemText(nId
) );
512 Sequence
<PropertyValue
> aPropVal(2);
513 PropertyValue
* pPropertyVal
= (PropertyValue
*)aPropVal
.getConstArray();
514 pPropertyVal
[0].Name
= C2U("QueryText");
515 rtl::OUString aSelection
= aEdQuery
.GetText();
516 pPropertyVal
[0].Value
<<= aSelection
;
517 pPropertyVal
[1].Name
=C2U("QueryField");
518 pPropertyVal
[1].Value
<<= aQueryField
;
519 SendDispatch(TBC_BT_AUTOFILTER
,aPropVal
);
523 MouseEvent
aLeave( aPoint
, 0, MOUSE_LEAVEWINDOW
| MOUSE_SYNTHETIC
);
525 SetItemDown(TBC_BT_AUTOFILTER
,sal_False
);
531 //-----------------------------------------------------------------------------
532 void BibToolBar::statusChanged(const frame::FeatureStateEvent
& rEvent
)
533 throw( uno::RuntimeException
)
535 for(sal_uInt16 i
= 0; i
< aListenerArr
.Count(); i
++)
537 BibToolBarListenerPtr pListener
= aListenerArr
.GetObject(i
);
538 (*pListener
)->statusChanged(rEvent
);
542 void BibToolBar::DataChanged( const DataChangedEvent
& rDCEvt
)
544 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
545 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
547 ToolBox::DataChanged( rDCEvt
);
550 IMPL_LINK( BibToolBar
, OptionsChanged_Impl
, void*, /*pVoid*/ )
552 sal_Bool bRebuildToolBar
= sal_False
;
553 sal_Int16 eSymbolsSize
= SvtMiscOptions().GetCurrentSymbolsSize();
554 if ( nSymbolsSize
!= eSymbolsSize
)
556 nSymbolsSize
= eSymbolsSize
;
557 bRebuildToolBar
= sal_True
;
559 else if ( nOutStyle
!= SvtMiscOptions().GetToolboxStyle() )
561 nOutStyle
= SvtMiscOptions().GetToolboxStyle();
562 SetOutStyle( nOutStyle
);
563 bRebuildToolBar
= sal_True
;
566 if ( bRebuildToolBar
)
572 //-----------------------------------------------------------------------------
574 IMPL_LINK( BibToolBar
, SettingsChanged_Impl
, void*, /*pVoid*/ )
576 // Check if toolbar button size have changed and we have to use system settings
577 sal_Int16 eSymbolsSize
= SvtMiscOptions().GetCurrentSymbolsSize();
578 if ( eSymbolsSize
!= nSymbolsSize
)
580 nSymbolsSize
= eSymbolsSize
;
587 //-----------------------------------------------------------------------------
588 void BibToolBar::RebuildToolbar()
591 // We have to call parent asynchronously as SetSize works also asynchronously!
592 Application::PostUserEvent( aLayoutManager
, 0 );
595 //-----------------------------------------------------------------------------
597 void BibToolBar::ApplyImageList()
599 ImageList
& rList
= ( nSymbolsSize
== SFX_SYMBOLS_SIZE_SMALL
) ?
603 SetItemImage(TBC_BT_AUTOFILTER
, rList
.GetImage(SID_FM_AUTOFILTER
));
604 SetItemImage(TBC_BT_FILTERCRIT
, rList
.GetImage(SID_FM_FILTERCRIT
));
605 SetItemImage(TBC_BT_REMOVEFILTER
, rList
.GetImage(SID_FM_REMOVE_FILTER_SORT
));
609 void BibToolBar::AdjustToolBox()
611 Size aOldSize
= GetSizePixel();
612 Size aSize
= CalcWindowSizePixel();
613 if ( !aSize
.Width() )
614 aSize
.Width() = aOldSize
.Width();
615 else if ( !aSize
.Height() )
616 aSize
.Height() = aOldSize
.Height();
618 Size aTbSize
= GetSizePixel();
620 (aSize
.Width() && aSize
.Width() != aTbSize
.Width()) ||
621 (aSize
.Height() && aSize
.Height() != aTbSize
.Height())
624 SetPosSizePixel( GetPosPixel(), aSize
);
629 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */