1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/processfactory.hxx>
21 #include <com/sun/star/frame/XDispatch.hpp>
22 #include <com/sun/star/frame/XDispatchProvider.hpp>
23 #include <com/sun/star/util/URLTransformer.hpp>
24 #include <com/sun/star/util/XURLTransformer.hpp>
25 #include <com/sun/star/frame/FrameSearchFlag.hpp>
27 #include <svx/svxids.hrc>
28 #include <svtools/miscopt.hxx>
29 #include <svtools/imgdef.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/mnemonic.hxx>
33 #include "bibbeam.hxx"
34 #include "bibview.hxx"
35 #include "toolbar.hrc"
36 #include "bibresid.hxx"
38 #include "bibtools.hxx"
39 #include <osl/mutex.hxx>
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::beans
;
46 // Konstanten -------------------------------------------------------------
49 BibToolBarListener::BibToolBarListener(BibToolBar
*pTB
, const OUString
& aStr
, sal_uInt16 nId
):
56 BibToolBarListener::~BibToolBarListener()
60 void BibToolBarListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& rEvt
)throw( ::com::sun::star::uno::RuntimeException
, std::exception
)
62 if(rEvt
.FeatureURL
.Complete
== aCommand
)
64 SolarMutexGuard aGuard
;
65 pToolBar
->EnableItem(nIndex
,rEvt
.IsEnabled
);
67 ::com::sun::star::uno::Any aState
=rEvt
.State
;
68 if(aState
.getValueType()==cppu::UnoType
<bool>::get())
70 bool bChecked
= *static_cast<sal_Bool
const *>(aState
.getValue());
71 pToolBar
->CheckItem(nIndex
, bChecked
);
78 BibTBListBoxListener::BibTBListBoxListener(BibToolBar
*pTB
, const OUString
& aStr
, sal_uInt16 nId
):
79 BibToolBarListener(pTB
,aStr
,nId
)
83 BibTBListBoxListener::~BibTBListBoxListener()
87 void BibTBListBoxListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& rEvt
)throw( ::com::sun::star::uno::RuntimeException
, std::exception
)
89 if(rEvt
.FeatureURL
.Complete
== GetCommand())
91 SolarMutexGuard aGuard
;
92 pToolBar
->EnableSourceList(rEvt
.IsEnabled
);
94 Any aState
= rEvt
.State
;
95 if(aState
.getValueType() == cppu::UnoType
<Sequence
<OUString
>>::get())
97 pToolBar
->UpdateSourceList(false);
98 pToolBar
->ClearSourceList();
100 Sequence
<OUString
> const * pStringSeq
= static_cast<Sequence
<OUString
> const *>(aState
.getValue());
101 const OUString
* pStringArray
= (const OUString
*)pStringSeq
->getConstArray();
103 sal_uInt32 nCount
= pStringSeq
->getLength();
105 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
107 aEntry
= pStringArray
[i
];
108 pToolBar
->InsertSourceEntry(aEntry
);
110 pToolBar
->UpdateSourceList(true);
113 pToolBar
->SelectSourceEntry(rEvt
.FeatureDescriptor
);
117 BibTBQueryMenuListener::BibTBQueryMenuListener(BibToolBar
*pTB
, const OUString
& aStr
, sal_uInt16 nId
):
118 BibToolBarListener(pTB
,aStr
,nId
)
122 BibTBQueryMenuListener::~BibTBQueryMenuListener()
126 void BibTBQueryMenuListener::statusChanged(const frame::FeatureStateEvent
& rEvt
)throw( uno::RuntimeException
, std::exception
)
128 if(rEvt
.FeatureURL
.Complete
== GetCommand())
130 SolarMutexGuard aGuard
;
131 pToolBar
->EnableSourceList(rEvt
.IsEnabled
);
133 uno::Any aState
=rEvt
.State
;
134 if(aState
.getValueType()==cppu::UnoType
<Sequence
<OUString
>>::get())
136 pToolBar
->ClearFilterMenu();
138 Sequence
<OUString
> const * pStringSeq
= static_cast<Sequence
<OUString
> const *>(aState
.getValue());
139 const OUString
* pStringArray
= (const OUString
*)pStringSeq
->getConstArray();
141 sal_uInt32 nCount
= pStringSeq
->getLength();
142 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
144 sal_uInt16 nID
= pToolBar
->InsertFilterItem(pStringArray
[i
]);
145 if(pStringArray
[i
]==rEvt
.FeatureDescriptor
)
147 pToolBar
->SelectFilterItem(nID
);
154 BibTBEditListener::BibTBEditListener(BibToolBar
*pTB
, const OUString
& aStr
, sal_uInt16 nId
):
155 BibToolBarListener(pTB
,aStr
,nId
)
159 BibTBEditListener::~BibTBEditListener()
163 void BibTBEditListener::statusChanged(const frame::FeatureStateEvent
& rEvt
)throw( uno::RuntimeException
, std::exception
)
165 if(rEvt
.FeatureURL
.Complete
== GetCommand())
167 SolarMutexGuard aGuard
;
168 pToolBar
->EnableQuery(rEvt
.IsEnabled
);
170 uno::Any aState
=rEvt
.State
;
171 if(aState
.getValueType()== ::cppu::UnoType
<OUString
>::get())
173 OUString aStr
= *static_cast<OUString
const *>(aState
.getValue());
174 pToolBar
->SetQueryString(aStr
);
179 BibToolBar::BibToolBar(vcl::Window
* pParent
, Link
<> aLink
, WinBits nStyle
):
180 ToolBox(pParent
,BibResId(RID_BIB_TOOLBAR
)),
181 aImgLst(BibResId( RID_TOOLBAR_IMGLIST
)),
182 aBigImgLst(BibResId( RID_TOOLBAR_BIGIMGLIST
)),
183 aFtSource(VclPtr
<FixedText
>::Create(this,WB_VCENTER
)),
184 aLBSource(VclPtr
<ListBox
>::Create(this,WB_DROPDOWN
)),
185 aFtQuery(VclPtr
<FixedText
>::Create(this,WB_VCENTER
)),
186 aEdQuery(VclPtr
<Edit
>::Create(this)),
189 aLayoutManager( aLink
),
190 nSymbolsSize( SFX_SYMBOLS_SIZE_SMALL
),
193 SvtMiscOptions aSvtMiscOptions
;
194 nSymbolsSize
= aSvtMiscOptions
.GetCurrentSymbolsSize();
195 nOutStyle
= aSvtMiscOptions
.GetToolboxStyle();
198 SetStyle(GetStyle()|nStyle
);
199 SetOutStyle(TOOLBOX_STYLE_FLAT
);
200 Size
a2Size(GetOutputSizePixel());
202 aLBSource
->SetSizePixel(a2Size
);
203 aLBSource
->SetDropDownLineCount(9);
205 aLBSource
->SetSelectHdl(LINK( this, BibToolBar
, SelHdl
));
207 SvtMiscOptions().AddListenerLink( LINK( this, BibToolBar
, OptionsChanged_Impl
) );
208 Application::AddEventListener( LINK( this, BibToolBar
, SettingsChanged_Impl
) );
210 aIdle
.SetIdleHdl(LINK( this, BibToolBar
, SendSelHdl
));
211 aIdle
.SetPriority(SchedulerPriority::LOWEST
);
213 SetDropdownClickHdl( LINK( this, BibToolBar
, MenuHdl
));
215 aEdQuery
->SetSizePixel(aLBSource
->GetSizePixel());
218 OUString aStr
=GetItemText(TBC_FT_SOURCE
);
219 aFtSource
->SetText(aStr
);
220 aFtSource
->SetSizePixel(aFtSource
->get_preferred_size());
221 aFtSource
->SetBackground(Wallpaper( COL_TRANSPARENT
));
223 aStr
=GetItemText(TBC_FT_QUERY
);
224 aFtQuery
->SetText(aStr
);
225 aFtQuery
->SetSizePixel(aFtQuery
->get_preferred_size());
226 aFtQuery
->SetBackground(Wallpaper( COL_TRANSPARENT
));
228 SetItemWindow(TBC_FT_SOURCE
, aFtSource
.get());
229 SetItemWindow(TBC_LB_SOURCE
, aLBSource
.get());
230 SetItemWindow(TBC_FT_QUERY
, aFtQuery
.get());
231 SetItemWindow(TBC_ED_QUERY
, aEdQuery
.get());
233 ::bib::AddToTaskPaneList( this );
236 BibToolBar::~BibToolBar()
241 void BibToolBar::dispose()
243 SvtMiscOptions().RemoveListenerLink( LINK( this, BibToolBar
, OptionsChanged_Impl
) );
244 Application::RemoveEventListener( LINK( this, BibToolBar
, SettingsChanged_Impl
) );
245 ::bib::RemoveFromTaskPaneList( this );
246 aFtSource
.disposeAndClear();
247 aFtQuery
.disposeAndClear();
248 aEdQuery
.disposeAndClear();
249 aLBSource
.disposeAndClear();
253 void BibToolBar::InitListener()
255 sal_uInt16 nCount
=GetItemCount();
257 uno::Reference
< frame::XDispatch
> xDisp(xController
,UNO_QUERY
);
258 uno::Reference
< util::XURLTransformer
> xTrans( util::URLTransformer::create(comphelper::getProcessComponentContext()) );
262 aQueryURL
.Complete
= ".uno:Bib/MenuFilter";
263 xTrans
->parseStrict( aQueryURL
);
264 BibToolBarListener
* pQuery
=new BibTBQueryMenuListener(this,aQueryURL
.Complete
,TBC_BT_AUTOFILTER
);
265 xDisp
->addStatusListener(uno::Reference
< frame::XStatusListener
> (pQuery
),aQueryURL
);
267 for(sal_uInt16 nPos
=0;nPos
<nCount
;nPos
++)
269 sal_uInt16 nId
=GetItemId(nPos
);
270 if(!nId
|| nId
==TBC_FT_SOURCE
|| nId
==TBC_FT_QUERY
)
274 aURL
.Complete
= GetItemCommand(nId
);
275 if(aURL
.Complete
.isEmpty())
278 xTrans
->parseStrict( aURL
);
280 BibToolBarListener
* pListener
=NULL
;
281 if(nId
==TBC_LB_SOURCE
)
283 pListener
=new BibTBListBoxListener(this,aURL
.Complete
,nId
);
285 else if(nId
==TBC_ED_QUERY
)
287 pListener
=new BibTBEditListener(this,aURL
.Complete
,nId
);
291 pListener
=new BibToolBarListener(this,aURL
.Complete
,nId
);
294 BibToolBarListenerRef
* pxInsert
= new uno::Reference
<frame::XStatusListener
>;
295 (*pxInsert
) = pListener
;
296 aListenerArr
.push_back( pxInsert
);
297 xDisp
->addStatusListener(uno::Reference
< frame::XStatusListener
> (pListener
),aURL
);
302 void BibToolBar::SetXController(const uno::Reference
< frame::XController
> & xCtr
)
309 void BibToolBar::Select()
311 sal_uInt16 nId
=GetCurItemId();
313 if(nId
!=TBC_BT_AUTOFILTER
)
315 SendDispatch(nId
,Sequence
<PropertyValue
>() );
319 Sequence
<PropertyValue
> aPropVal(2);
320 PropertyValue
* pPropertyVal
= const_cast<PropertyValue
*>(aPropVal
.getConstArray());
321 pPropertyVal
[0].Name
="QueryText";
322 OUString aSelection
= aEdQuery
->GetText();
323 pPropertyVal
[0].Value
<<= aSelection
;
325 pPropertyVal
[1].Name
="QueryField";
326 pPropertyVal
[1].Value
<<= aQueryField
;
327 SendDispatch(nId
,aPropVal
);
331 void BibToolBar::SendDispatch(sal_uInt16 nId
, const Sequence
< PropertyValue
>& rArgs
)
333 OUString aCommand
= GetItemCommand(nId
);
335 uno::Reference
< frame::XDispatchProvider
> xDSP( xController
, UNO_QUERY
);
337 if( xDSP
.is() && !aCommand
.isEmpty())
339 uno::Reference
< util::XURLTransformer
> xTrans( util::URLTransformer::create(comphelper::getProcessComponentContext()) );
344 aURL
.Complete
= aCommand
;
346 xTrans
->parseStrict( aURL
);
348 uno::Reference
< frame::XDispatch
> xDisp
= xDSP
->queryDispatch( aURL
, OUString(), frame::FrameSearchFlag::SELF
);
351 xDisp
->dispatch( aURL
, rArgs
);
357 void BibToolBar::Click()
359 sal_uInt16 nId
=GetCurItemId();
361 if(nId
== TBC_BT_COL_ASSIGN
)
364 pDatMan
->CreateMappingDialog(GetParent());
365 CheckItem( nId
, false );
367 else if(nId
== TBC_BT_CHANGESOURCE
)
371 OUString sNew
= pDatMan
->CreateDBChangeDialog(GetParent());
373 pDatMan
->setActiveDataSource(sNew
);
375 CheckItem( nId
, false );
379 void BibToolBar::ClearFilterMenu()
384 sal_uInt16
BibToolBar::InsertFilterItem(const OUString
& aMenuEntry
)
387 aPopupMenu
.InsertItem(nMenuId
,aMenuEntry
);
391 void BibToolBar::SelectFilterItem(sal_uInt16 nId
)
393 aPopupMenu
.CheckItem(nId
);
395 aQueryField
= MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu
.GetItemText(nId
) );
398 void BibToolBar::EnableSourceList(bool bFlag
)
400 aFtSource
->Enable(bFlag
);
401 aLBSource
->Enable(bFlag
);
404 void BibToolBar::ClearSourceList()
409 void BibToolBar::UpdateSourceList(bool bFlag
)
411 aLBSource
->SetUpdateMode(bFlag
);
414 void BibToolBar::InsertSourceEntry(const OUString
& aEntry
, sal_Int32 nPos
)
416 aLBSource
->InsertEntry(aEntry
, nPos
);
419 void BibToolBar::SelectSourceEntry(const OUString
& aStr
)
421 aLBSource
->SelectEntry(aStr
);
424 void BibToolBar::EnableQuery(bool bFlag
)
426 aFtQuery
->Enable(bFlag
);
427 aEdQuery
->Enable(bFlag
);
430 void BibToolBar::SetQueryString(const OUString
& aStr
)
432 aEdQuery
->SetText(aStr
);
436 bool BibToolBar::PreNotify( NotifyEvent
& rNEvt
)
440 MouseNotifyEvent nSwitch
=rNEvt
.GetType();
441 if(aEdQuery
->HasFocus() && nSwitch
==MouseNotifyEvent::KEYINPUT
)
443 const vcl::KeyCode
& aKeyCode
=rNEvt
.GetKeyEvent()->GetKeyCode();
444 sal_uInt16 nKey
= aKeyCode
.GetCode();
445 if(nKey
== KEY_RETURN
)
447 Sequence
<PropertyValue
> aPropVal(2);
448 PropertyValue
* pPropertyVal
= const_cast<PropertyValue
*>(aPropVal
.getConstArray());
449 pPropertyVal
[0].Name
= "QueryText";
450 OUString aSelection
= aEdQuery
->GetText();
451 pPropertyVal
[0].Value
<<= aSelection
;
452 pPropertyVal
[1].Name
="QueryField";
453 pPropertyVal
[1].Value
<<= aQueryField
;
454 SendDispatch(TBC_BT_AUTOFILTER
,aPropVal
);
460 nResult
=ToolBox::PreNotify(rNEvt
);
465 IMPL_LINK( BibToolBar
, SelHdl
, ListBox
*, /*pLb*/ )
471 IMPL_LINK_NOARG_TYPED( BibToolBar
, SendSelHdl
, Idle
*, void )
473 Sequence
<PropertyValue
> aPropVal(1);
474 PropertyValue
* pPropertyVal
= const_cast<PropertyValue
*>(aPropVal
.getConstArray());
475 pPropertyVal
[0].Name
= "DataSourceName";
476 OUString
aEntry( MnemonicGenerator::EraseAllMnemonicChars( aLBSource
->GetSelectEntry() ) );
477 OUString aSelection
= aEntry
;
478 pPropertyVal
[0].Value
<<= aSelection
;
479 SendDispatch(TBC_LB_SOURCE
,aPropVal
);
482 IMPL_LINK_NOARG_TYPED( BibToolBar
, MenuHdl
, ToolBox
*, void)
484 sal_uInt16 nId
=GetCurItemId();
485 if(nId
==TBC_BT_AUTOFILTER
)
487 EndSelection(); // vor SetDropMode (SetDropMode ruft SetItemImage)
489 SetItemDown(TBC_BT_AUTOFILTER
,true);
490 nId
= aPopupMenu
.Execute(this, GetItemRect(TBC_BT_AUTOFILTER
));
495 aPopupMenu
.CheckItem(nSelMenuItem
,false);
496 aPopupMenu
.CheckItem(nId
);
498 aQueryField
= MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu
.GetItemText(nId
) );
499 Sequence
<PropertyValue
> aPropVal(2);
500 PropertyValue
* pPropertyVal
= const_cast<PropertyValue
*>(aPropVal
.getConstArray());
501 pPropertyVal
[0].Name
= "QueryText";
502 OUString aSelection
= aEdQuery
->GetText();
503 pPropertyVal
[0].Value
<<= aSelection
;
504 pPropertyVal
[1].Name
="QueryField";
505 pPropertyVal
[1].Value
<<= aQueryField
;
506 SendDispatch(TBC_BT_AUTOFILTER
,aPropVal
);
510 MouseEvent
aLeave( aPoint
, 0, MouseEventModifiers::LEAVEWINDOW
| MouseEventModifiers::SYNTHETIC
);
512 SetItemDown(TBC_BT_AUTOFILTER
,false);
518 void BibToolBar::statusChanged(const frame::FeatureStateEvent
& rEvent
)
519 throw( uno::RuntimeException
)
521 for(sal_uInt16 i
= 0; i
< aListenerArr
.size(); i
++)
523 BibToolBarListenerRef
* pListener
= &aListenerArr
[i
];
524 (*pListener
)->statusChanged(rEvent
);
528 void BibToolBar::DataChanged( const DataChangedEvent
& rDCEvt
)
530 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
531 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
533 ToolBox::DataChanged( rDCEvt
);
536 IMPL_LINK_NOARG( BibToolBar
, OptionsChanged_Impl
)
538 bool bRebuildToolBar
= false;
539 sal_Int16 eSymbolsSize
= SvtMiscOptions().GetCurrentSymbolsSize();
540 if ( nSymbolsSize
!= eSymbolsSize
)
542 nSymbolsSize
= eSymbolsSize
;
543 bRebuildToolBar
= true;
545 else if ( nOutStyle
!= SvtMiscOptions().GetToolboxStyle() )
547 nOutStyle
= SvtMiscOptions().GetToolboxStyle();
548 SetOutStyle( nOutStyle
);
549 bRebuildToolBar
= true;
552 if ( bRebuildToolBar
)
560 IMPL_LINK_NOARG( BibToolBar
, SettingsChanged_Impl
)
562 // Check if toolbar button size have changed and we have to use system settings
563 sal_Int16 eSymbolsSize
= SvtMiscOptions().GetCurrentSymbolsSize();
564 if ( eSymbolsSize
!= nSymbolsSize
)
566 nSymbolsSize
= eSymbolsSize
;
574 void BibToolBar::RebuildToolbar()
577 // We have to call parent asynchronously as SetSize works also asynchronously!
578 Application::PostUserEvent( aLayoutManager
, 0 );
583 void BibToolBar::ApplyImageList()
585 ImageList
& rList
= ( nSymbolsSize
== SFX_SYMBOLS_SIZE_SMALL
) ?
589 SetItemImage(TBC_BT_AUTOFILTER
, rList
.GetImage(SID_FM_AUTOFILTER
));
590 SetItemImage(TBC_BT_FILTERCRIT
, rList
.GetImage(SID_FM_FILTERCRIT
));
591 SetItemImage(TBC_BT_REMOVEFILTER
, rList
.GetImage(SID_FM_REMOVE_FILTER_SORT
));
595 void BibToolBar::AdjustToolBox()
597 Size aOldSize
= GetSizePixel();
598 Size aSize
= CalcWindowSizePixel();
599 if ( !aSize
.Width() )
600 aSize
.Width() = aOldSize
.Width();
601 else if ( !aSize
.Height() )
602 aSize
.Height() = aOldSize
.Height();
604 Size aTbSize
= GetSizePixel();
606 (aSize
.Width() && aSize
.Width() != aTbSize
.Width()) ||
607 (aSize
.Height() && aSize
.Height() != aTbSize
.Height())
610 SetPosSizePixel( GetPosPixel(), aSize
);
615 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */