merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / bibliography / toolbar.cxx
blobcae06e153fe8673e6cabcffbfd04189f8507a864
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: toolbar.cxx,v $
10 * $Revision: 1.23 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include <comphelper/processfactory.hxx>
34 #include <osl/mutex.hxx>
35 #include <tools/urlobj.hxx>
36 #include <com/sun/star/frame/XDispatch.hpp>
37 #include <com/sun/star/frame/XDispatchProvider.hpp>
38 #include <com/sun/star/util/XURLTransformer.hpp>
39 #include <com/sun/star/frame/FrameSearchFlag.hpp>
40 #include <datman.hxx>
41 #include <tools/debug.hxx>
42 #ifndef _SVX_SVXIDS_HRC
43 #include <svx/svxids.hrc>
44 #endif
45 #include <svtools/miscopt.hxx>
46 #include <svtools/imgdef.hxx>
47 #include <vcl/svapp.hxx>
48 #include <vcl/mnemonic.hxx>
49 #include "bibbeam.hxx"
50 #include "toolbar.hrc"
51 #include "bibresid.hxx"
53 #ifndef BIBTOOLS_HXX
54 #include "bibtools.hxx"
55 #endif
56 #include <vos/mutex.hxx>
58 using namespace ::rtl;
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::beans;
62 #define C2U(cChar) OUString::createFromAscii(cChar)
65 // Konstanten -------------------------------------------------------------
68 BibToolBarListener::BibToolBarListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
69 nIndex(nId),
70 aCommand(aStr),
71 pToolBar(pTB)
75 BibToolBarListener::~BibToolBarListener()
79 void BibToolBarListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& rEvt)throw( ::com::sun::star::uno::RuntimeException )
81 if(rEvt.FeatureURL.Complete == aCommand)
83 vos::OGuard aGuard(Application::GetSolarMutex());
84 pToolBar->EnableItem(nIndex,rEvt.IsEnabled);
86 ::com::sun::star::uno::Any aState=rEvt.State;
87 if(aState.getValueType()==::getBooleanCppuType())
89 sal_Bool bChecked= *(sal_Bool*)aState.getValue();
90 pToolBar->CheckItem(nIndex, bChecked);
94 rtl::OUString FeatureDescriptor;
95 sal_Bool Requery;
96 ::com::sun::star::uno::Any State;*/
100 rtl::OUString BibToolBarListener::GetCommand()
102 return aCommand;
105 BibTBListBoxListener::BibTBListBoxListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
106 BibToolBarListener(pTB,aStr,nId)
110 BibTBListBoxListener::~BibTBListBoxListener()
114 void BibTBListBoxListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& rEvt)throw( ::com::sun::star::uno::RuntimeException )
116 if(rEvt.FeatureURL.Complete == GetCommand())
118 vos::OGuard aGuard(Application::GetSolarMutex());
119 pToolBar->EnableSourceList(rEvt.IsEnabled);
121 Any aState = rEvt.State;
122 if(aState.getValueType() == ::getCppuType((Sequence<rtl::OUString>*)0))
124 pToolBar->UpdateSourceList(sal_False);
125 pToolBar->ClearSourceList();
127 Sequence<rtl::OUString>* pStringSeq = (Sequence<rtl::OUString>*)aState.getValue();
128 const rtl::OUString* pStringArray = (const rtl::OUString*)pStringSeq->getConstArray();
130 sal_uInt32 nCount = pStringSeq->getLength();
131 XubString aEntry;
132 for( sal_uInt32 i=0; i<nCount; i++ )
134 aEntry = String(pStringArray[i]);
135 pToolBar->InsertSourceEntry(aEntry);
137 pToolBar->UpdateSourceList(sal_True);
140 XubString aStr = String(rEvt.FeatureDescriptor);
141 pToolBar->SelectSourceEntry(aStr);
145 BibTBQueryMenuListener::BibTBQueryMenuListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
146 BibToolBarListener(pTB,aStr,nId)
150 BibTBQueryMenuListener::~BibTBQueryMenuListener()
154 void BibTBQueryMenuListener::statusChanged(const frame::FeatureStateEvent& rEvt)throw( uno::RuntimeException )
156 if(rEvt.FeatureURL.Complete == GetCommand())
158 vos::OGuard aGuard(Application::GetSolarMutex());
159 pToolBar->EnableSourceList(rEvt.IsEnabled);
161 uno::Any aState=rEvt.State;
162 if(aState.getValueType()==::getCppuType((Sequence<rtl::OUString>*)0))
164 pToolBar->ClearFilterMenu();
166 Sequence<rtl::OUString>* pStringSeq = (Sequence<rtl::OUString>*) aState.getValue();
167 const rtl::OUString* pStringArray = (const rtl::OUString*)pStringSeq->getConstArray();
169 sal_uInt32 nCount = pStringSeq->getLength();
170 for( sal_uInt32 i=0; i<nCount; i++ )
172 sal_uInt16 nID=pToolBar->InsertFilterItem(String(pStringArray[i]));
173 if(pStringArray[i]==rEvt.FeatureDescriptor)
175 // XubString aStr = rEvt.FeatureDescriptor;
176 pToolBar->SelectFilterItem(nID);
183 BibTBEditListener::BibTBEditListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
184 BibToolBarListener(pTB,aStr,nId)
188 BibTBEditListener::~BibTBEditListener()
192 void BibTBEditListener::statusChanged(const frame::FeatureStateEvent& rEvt)throw( uno::RuntimeException )
194 if(rEvt.FeatureURL.Complete == GetCommand())
196 vos::OGuard aGuard(Application::GetSolarMutex());
197 pToolBar->EnableQuery(rEvt.IsEnabled);
199 uno::Any aState=rEvt.State;
200 if(aState.getValueType()==::getCppuType((const OUString*)0))
202 String aStr = String(*(OUString*) aState.getValue());
203 pToolBar->SetQueryString(aStr);
208 SV_IMPL_PTRARR( BibToolBarListenerArr, BibToolBarListenerPtr);
210 BibToolBar::BibToolBar(Window* pParent, Link aLink, WinBits nStyle):
211 ToolBox(pParent,BibResId(RID_BIB_TOOLBAR)),
212 aImgLst(BibResId( RID_TOOLBAR_IMGLIST )),
213 aImgLstHC(BibResId(RID_TOOLBAR_IMGLIST_HC )),
214 aBigImgLst(BibResId( RID_TOOLBAR_BIGIMGLIST )),
215 aBigImgLstHC(BibResId( RID_TOOLBAR_BIGIMGLIST_HC )),
216 aFtSource(this,WB_VCENTER),
217 aLBSource(this,WB_DROPDOWN),
218 aFtQuery(this,WB_VCENTER),
219 aEdQuery(this),
220 nMenuId(0),
221 nSelMenuItem(0),
222 aLayoutManager( aLink ),
223 nSymbolsSize( SFX_SYMBOLS_SIZE_SMALL ),
224 nOutStyle( 0 )
226 SvtMiscOptions aSvtMiscOptions;
227 nSymbolsSize = aSvtMiscOptions.GetCurrentSymbolsSize();
228 nOutStyle = aSvtMiscOptions.GetToolboxStyle();
230 ApplyImageList();
231 SetStyle(GetStyle()|nStyle);
232 SetOutStyle(TOOLBOX_STYLE_FLAT);
233 Size aSize=GetSizePixel();
234 Size a2Size(GetOutputSizePixel());
235 a2Size.Width()=100;
236 aLBSource.SetSizePixel(a2Size);
237 aLBSource.SetDropDownLineCount(9);
238 aLBSource.Show();
239 aLBSource.SetSelectHdl(LINK( this, BibToolBar, SelHdl));
241 SvtMiscOptions().AddListener( LINK( this, BibToolBar, OptionsChanged_Impl ) );
242 Application::AddEventListener( LINK( this, BibToolBar, SettingsChanged_Impl ) );
244 aTimer.SetTimeoutHdl(LINK( this, BibToolBar, SendSelHdl));
245 aTimer.SetTimeout(400);
247 SetDropdownClickHdl( LINK( this, BibToolBar, MenuHdl));
249 aEdQuery.SetSizePixel(aLBSource.GetSizePixel());
250 aEdQuery.Show();
252 XubString aStr=GetItemText(TBC_FT_SOURCE);
253 Rectangle aRect=GetItemRect(TBC_FT_SOURCE);
254 aFtSource.SetText(aStr);
255 aFtSource.SetSizePixel(aRect.GetSize());
256 aFtSource.SetBackground(Wallpaper( COL_TRANSPARENT ));
258 aStr=GetItemText(TBC_FT_QUERY);
259 aRect=GetItemRect(TBC_FT_QUERY);
260 aFtQuery.SetText(aStr);
261 aFtQuery.SetSizePixel(aRect.GetSize());
262 aFtQuery.SetBackground(Wallpaper( COL_TRANSPARENT ));
264 SetItemWindow(TBC_FT_SOURCE,&aFtSource);
265 SetItemWindow(TBC_LB_SOURCE,&aLBSource);
266 SetItemWindow(TBC_FT_QUERY ,&aFtQuery);
267 SetItemWindow(TBC_ED_QUERY ,&aEdQuery);
269 ::bib::AddToTaskPaneList( this );
272 BibToolBar::~BibToolBar()
274 SvtMiscOptions().RemoveListener( LINK( this, BibToolBar, OptionsChanged_Impl ) );
275 Application::RemoveEventListener( LINK( this, BibToolBar, SettingsChanged_Impl ) );
276 ::bib::RemoveFromTaskPaneList( this );
279 void BibToolBar::InitListener()
281 sal_uInt16 nCount=GetItemCount();
283 uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
284 uno::Reference< frame::XDispatch > xDisp(xController,UNO_QUERY);
286 uno::Reference< util::XURLTransformer > xTrans ( xMgr->createInstance( C2U("com.sun.star.util.URLTransformer") ), UNO_QUERY );
287 if( xTrans.is() )
289 util::URL aQueryURL;
290 aQueryURL.Complete = C2U(".uno:Bib/MenuFilter");
291 xTrans->parseStrict( aQueryURL);
292 BibToolBarListener* pQuery=new BibTBQueryMenuListener(this,aQueryURL.Complete,TBC_BT_AUTOFILTER);
293 xDisp->addStatusListener(uno::Reference< frame::XStatusListener > (pQuery),aQueryURL);
295 for(sal_uInt16 nPos=0;nPos<nCount;nPos++)
297 sal_uInt16 nId=GetItemId(nPos);
298 if(!nId || nId==TBC_FT_SOURCE || nId==TBC_FT_QUERY)
299 continue;
301 util::URL aURL;
302 aURL.Complete = GetItemCommand(nId);
303 if(!aURL.Complete.getLength())
304 continue;
306 xTrans->parseStrict( aURL );
308 BibToolBarListener* pListener=NULL;
309 if(nId==TBC_LB_SOURCE)
311 pListener=new BibTBListBoxListener(this,aURL.Complete,nId);
313 else if(nId==TBC_ED_QUERY)
315 pListener=new BibTBEditListener(this,aURL.Complete,nId);
317 else
319 pListener=new BibToolBarListener(this,aURL.Complete,nId);
322 BibToolBarListenerPtr pxInsert = new Reference<frame::XStatusListener>;
323 (*pxInsert) = pListener;
324 aListenerArr.Insert( pxInsert, aListenerArr.Count() );
325 xDisp->addStatusListener(uno::Reference< frame::XStatusListener > (pListener),aURL);
330 void BibToolBar::SetXController(const uno::Reference< frame::XController > & xCtr)
332 xController=xCtr;
333 InitListener();
337 void BibToolBar::Select()
339 sal_uInt16 nId=GetCurItemId();
341 if(nId!=TBC_BT_AUTOFILTER)
343 SendDispatch(nId,Sequence<PropertyValue>() );
345 else
347 Sequence<PropertyValue> aPropVal(2);
348 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
349 pPropertyVal[0].Name=C2U("QueryText");
350 rtl::OUString aSelection = aEdQuery.GetText();
351 pPropertyVal[0].Value <<= aSelection;
353 pPropertyVal[1].Name=C2U("QueryField");
354 pPropertyVal[1].Value <<= aQueryField;
355 SendDispatch(nId,aPropVal);
359 void BibToolBar::SendDispatch(sal_uInt16 nId, const Sequence< PropertyValue >& rArgs)
361 rtl::OUString aCommand = GetItemCommand(nId);
363 uno::Reference< frame::XDispatchProvider > xDSP( xController, UNO_QUERY );
365 if( xDSP.is() && aCommand.getLength())
367 uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
369 uno::Reference< util::XURLTransformer > xTrans ( xMgr->createInstance( C2U("com.sun.star.util.URLTransformer") ), UNO_QUERY );
370 if( xTrans.is() )
372 // Datei laden
373 util::URL aURL;
374 aURL.Complete = aCommand;
376 xTrans->parseStrict( aURL );
378 uno::Reference< frame::XDispatch > xDisp = xDSP->queryDispatch( aURL, rtl::OUString(), frame::FrameSearchFlag::SELF );
380 if ( xDisp.is() )
381 xDisp->dispatch( aURL, rArgs);
387 void BibToolBar::Click()
389 sal_uInt16 nId=GetCurItemId();
391 if(nId == TBC_BT_COL_ASSIGN )
393 if(pDatMan)
394 pDatMan->CreateMappingDialog(GetParent());
395 CheckItem( nId, FALSE );
397 else if(nId == TBC_BT_CHANGESOURCE)
399 if(pDatMan)
401 OUString sNew = pDatMan->CreateDBChangeDialog(GetParent());
402 if(sNew.getLength())
403 pDatMan->setActiveDataSource(sNew);
405 CheckItem( nId, FALSE );
409 void BibToolBar::ClearFilterMenu()
411 aPopupMenu.Clear();
412 nMenuId=0;
414 sal_uInt16 BibToolBar::InsertFilterItem(const XubString& aMenuEntry)
416 nMenuId++;
417 aPopupMenu.InsertItem(nMenuId,aMenuEntry);
419 return nMenuId;
421 void BibToolBar::SelectFilterItem(sal_uInt16 nId)
423 aPopupMenu.CheckItem(nId);
424 nSelMenuItem=nId;
425 aQueryField = MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu.GetItemText(nId) );
428 void BibToolBar::EnableSourceList(sal_Bool bFlag)
430 aFtSource.Enable(bFlag);
431 aLBSource.Enable(bFlag);
434 void BibToolBar::ClearSourceList()
436 aLBSource.Clear();
439 void BibToolBar::UpdateSourceList(sal_Bool bFlag)
441 aLBSource.SetUpdateMode(bFlag);
444 void BibToolBar::InsertSourceEntry(const XubString& aEntry, sal_uInt16 nPos)
446 aLBSource.InsertEntry(aEntry, nPos);
449 void BibToolBar::SelectSourceEntry(const XubString& aStr)
451 aLBSource.SelectEntry(aStr);
454 void BibToolBar::EnableQuery(sal_Bool bFlag)
456 aFtQuery.Enable(bFlag);
457 aEdQuery.Enable(bFlag);
460 void BibToolBar::SetQueryString(const XubString& aStr)
462 aEdQuery.SetText(aStr);
466 long BibToolBar::PreNotify( NotifyEvent& rNEvt )
468 long nResult=sal_True;
470 sal_uInt16 nSwitch=rNEvt.GetType();
471 if(aEdQuery.HasFocus() && nSwitch==EVENT_KEYINPUT)// || nSwitch==EVENT_KEYUP)
473 const KeyCode& aKeyCode=rNEvt.GetKeyEvent()->GetKeyCode();
474 sal_uInt16 nKey = aKeyCode.GetCode();
475 if(nKey == KEY_RETURN)
477 Sequence<PropertyValue> aPropVal(2);
478 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
479 pPropertyVal[0].Name = C2U("QueryText");
480 rtl::OUString aSelection = aEdQuery.GetText();
481 pPropertyVal[0].Value <<= aSelection;
482 pPropertyVal[1].Name=C2U("QueryField");
483 pPropertyVal[1].Value <<= aQueryField;
484 SendDispatch(TBC_BT_AUTOFILTER,aPropVal);
485 return nResult;
490 nResult=ToolBox::PreNotify(rNEvt);
492 return nResult;
495 IMPL_LINK( BibToolBar, SelHdl, ListBox*, /*pLb*/ )
497 aTimer.Start();
498 return 0;
501 IMPL_LINK( BibToolBar, SendSelHdl, Timer*,/*pT*/)
503 Sequence<PropertyValue> aPropVal(1);
504 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
505 pPropertyVal[0].Name = C2U("DataSourceName");
506 String aEntry( MnemonicGenerator::EraseAllMnemonicChars( aLBSource.GetSelectEntry() ) );
507 rtl::OUString aSelection = aEntry;
508 pPropertyVal[0].Value <<= aSelection;
509 SendDispatch(TBC_LB_SOURCE,aPropVal);
511 return 0;
513 //-----------------------------------------------------------------------------
514 IMPL_LINK( BibToolBar, MenuHdl, ToolBox*, /*pToolbox*/)
516 sal_uInt16 nId=GetCurItemId();
517 if(nId==TBC_BT_AUTOFILTER)
519 EndSelection(); // vor SetDropMode (SetDropMode ruft SetItemImage)
521 SetItemDown(TBC_BT_AUTOFILTER,sal_True);
522 nId = aPopupMenu.Execute(this, GetItemRect(TBC_BT_AUTOFILTER));
525 if(nId>0)
527 aPopupMenu.CheckItem(nSelMenuItem,sal_False);
528 aPopupMenu.CheckItem(nId);
529 nSelMenuItem=nId;
530 aQueryField = MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu.GetItemText(nId) );
531 Sequence<PropertyValue> aPropVal(2);
532 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
533 pPropertyVal[0].Name = C2U("QueryText");
534 rtl::OUString aSelection = aEdQuery.GetText();
535 pPropertyVal[0].Value <<= aSelection;
536 pPropertyVal[1].Name=C2U("QueryField");
537 pPropertyVal[1].Value <<= aQueryField;
538 SendDispatch(TBC_BT_AUTOFILTER,aPropVal);
541 Point aPoint;
542 MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
543 MouseMove( aLeave );
544 SetItemDown(TBC_BT_AUTOFILTER,sal_False);
548 return 0;
550 //-----------------------------------------------------------------------------
551 void BibToolBar::statusChanged(const frame::FeatureStateEvent& rEvent)
552 throw( uno::RuntimeException )
554 for(sal_uInt16 i = 0; i < aListenerArr.Count(); i++)
556 BibToolBarListenerPtr pListener = aListenerArr.GetObject(i);
557 (*pListener)->statusChanged(rEvent);
560 /* -----------------------------07.05.2002 15:08------------------------------
562 ---------------------------------------------------------------------------*/
563 void BibToolBar::DataChanged( const DataChangedEvent& rDCEvt )
565 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
566 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
567 ApplyImageList();
568 ToolBox::DataChanged( rDCEvt );
570 /* -----------------------------07.05.2002 15:09------------------------------
571 ---------------------------------------------------------------------------*/
573 IMPL_LINK( BibToolBar, OptionsChanged_Impl, void*, /*pVoid*/ )
575 sal_Bool bRebuildToolBar = sal_False;
576 sal_Int16 eSymbolsSize = SvtMiscOptions().GetCurrentSymbolsSize();
577 if ( nSymbolsSize != eSymbolsSize )
579 nSymbolsSize = eSymbolsSize;
580 bRebuildToolBar = sal_True;
582 else if ( nOutStyle != SvtMiscOptions().GetToolboxStyle() )
584 nOutStyle = SvtMiscOptions().GetToolboxStyle();
585 SetOutStyle( nOutStyle );
586 bRebuildToolBar = sal_True;
589 if ( bRebuildToolBar )
590 RebuildToolbar();
592 return 0L;
595 //-----------------------------------------------------------------------------
597 IMPL_LINK( BibToolBar, SettingsChanged_Impl, void*, /*pVoid*/ )
599 // Check if toolbar button size have changed and we have to use system settings
600 sal_Int16 eSymbolsSize = SvtMiscOptions().GetCurrentSymbolsSize();
601 if ( eSymbolsSize != nSymbolsSize )
603 nSymbolsSize = eSymbolsSize;
604 RebuildToolbar();
607 return 0L;
610 //-----------------------------------------------------------------------------
611 void BibToolBar::RebuildToolbar()
613 ApplyImageList();
614 // We have to call parent asynchronously as SetSize works also asynchronously!
615 Application::PostUserEvent( aLayoutManager, 0 );
618 //-----------------------------------------------------------------------------
620 void BibToolBar::ApplyImageList()
622 ImageList& rList = ( nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ) ?
623 ( GetDisplayBackground().GetColor().IsDark() ? aImgLstHC : aImgLst ) :
624 ( GetDisplayBackground().GetColor().IsDark() ? aBigImgLstHC : aBigImgLst );
626 SetItemImage(TBC_BT_AUTOFILTER , rList.GetImage(SID_FM_AUTOFILTER));
627 SetItemImage(TBC_BT_FILTERCRIT , rList.GetImage(SID_FM_FILTERCRIT));
628 SetItemImage(TBC_BT_REMOVEFILTER, rList.GetImage(SID_FM_REMOVE_FILTER_SORT ));
629 AdjustToolBox();
632 void BibToolBar::AdjustToolBox()
634 Size aOldSize = GetSizePixel();
635 Size aSize = CalcWindowSizePixel();
636 if ( !aSize.Width() )
637 aSize.Width() = aOldSize.Width();
638 else if ( !aSize.Height() )
639 aSize.Height() = aOldSize.Height();
641 Size aTbSize = GetSizePixel();
642 if (
643 (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
644 (aSize.Height() && aSize.Height() != aTbSize.Height())
647 SetPosSizePixel( GetPosPixel(), aSize );
648 Invalidate();