Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / extensions / source / bibliography / toolbar.cxx
blob98931799c97d59bdab3f7aa5792e3a73ff36d072
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <datman.hxx>
27 #include <svx/svxids.hrc>
28 #include <svtools/miscopt.hxx>
29 #include <svtools/imgdef.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/mnemonic.hxx>
32 #include "bibbeam.hxx"
33 #include "toolbar.hrc"
34 #include "bibresid.hxx"
36 #include "bibtools.hxx"
37 #include <osl/mutex.hxx>
39 using namespace ::rtl;
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::beans;
43 #define C2U(cChar) OUString::createFromAscii(cChar)
46 // Konstanten -------------------------------------------------------------
49 BibToolBarListener::BibToolBarListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
50 nIndex(nId),
51 aCommand(aStr),
52 pToolBar(pTB)
56 BibToolBarListener::~BibToolBarListener()
60 void BibToolBarListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& rEvt)throw( ::com::sun::star::uno::RuntimeException )
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()==::getBooleanCppuType())
70 sal_Bool bChecked= *(sal_Bool*)aState.getValue();
71 pToolBar->CheckItem(nIndex, bChecked);
77 rtl::OUString BibToolBarListener::GetCommand() const
79 return aCommand;
82 BibTBListBoxListener::BibTBListBoxListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
83 BibToolBarListener(pTB,aStr,nId)
87 BibTBListBoxListener::~BibTBListBoxListener()
91 void BibTBListBoxListener::statusChanged(const ::com::sun::star::frame::FeatureStateEvent& rEvt)throw( ::com::sun::star::uno::RuntimeException )
93 if(rEvt.FeatureURL.Complete == GetCommand())
95 SolarMutexGuard aGuard;
96 pToolBar->EnableSourceList(rEvt.IsEnabled);
98 Any aState = rEvt.State;
99 if(aState.getValueType() == ::getCppuType((Sequence<rtl::OUString>*)0))
101 pToolBar->UpdateSourceList(sal_False);
102 pToolBar->ClearSourceList();
104 Sequence<rtl::OUString>* pStringSeq = (Sequence<rtl::OUString>*)aState.getValue();
105 const rtl::OUString* pStringArray = (const rtl::OUString*)pStringSeq->getConstArray();
107 sal_uInt32 nCount = pStringSeq->getLength();
108 XubString aEntry;
109 for( sal_uInt32 i=0; i<nCount; i++ )
111 aEntry = String(pStringArray[i]);
112 pToolBar->InsertSourceEntry(aEntry);
114 pToolBar->UpdateSourceList(sal_True);
117 XubString aStr = String(rEvt.FeatureDescriptor);
118 pToolBar->SelectSourceEntry(aStr);
122 BibTBQueryMenuListener::BibTBQueryMenuListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
123 BibToolBarListener(pTB,aStr,nId)
127 BibTBQueryMenuListener::~BibTBQueryMenuListener()
131 void BibTBQueryMenuListener::statusChanged(const frame::FeatureStateEvent& rEvt)throw( uno::RuntimeException )
133 if(rEvt.FeatureURL.Complete == GetCommand())
135 SolarMutexGuard aGuard;
136 pToolBar->EnableSourceList(rEvt.IsEnabled);
138 uno::Any aState=rEvt.State;
139 if(aState.getValueType()==::getCppuType((Sequence<rtl::OUString>*)0))
141 pToolBar->ClearFilterMenu();
143 Sequence<rtl::OUString>* pStringSeq = (Sequence<rtl::OUString>*) aState.getValue();
144 const rtl::OUString* pStringArray = (const rtl::OUString*)pStringSeq->getConstArray();
146 sal_uInt32 nCount = pStringSeq->getLength();
147 for( sal_uInt32 i=0; i<nCount; i++ )
149 sal_uInt16 nID=pToolBar->InsertFilterItem(String(pStringArray[i]));
150 if(pStringArray[i]==rEvt.FeatureDescriptor)
152 pToolBar->SelectFilterItem(nID);
159 BibTBEditListener::BibTBEditListener(BibToolBar *pTB,rtl::OUString aStr,sal_uInt16 nId):
160 BibToolBarListener(pTB,aStr,nId)
164 BibTBEditListener::~BibTBEditListener()
168 void BibTBEditListener::statusChanged(const frame::FeatureStateEvent& rEvt)throw( uno::RuntimeException )
170 if(rEvt.FeatureURL.Complete == GetCommand())
172 SolarMutexGuard aGuard;
173 pToolBar->EnableQuery(rEvt.IsEnabled);
175 uno::Any aState=rEvt.State;
176 if(aState.getValueType()==::getCppuType((const OUString*)0))
178 String aStr = String(*(OUString*) aState.getValue());
179 pToolBar->SetQueryString(aStr);
184 BibToolBar::BibToolBar(Window* pParent, Link aLink, WinBits nStyle):
185 ToolBox(pParent,BibResId(RID_BIB_TOOLBAR)),
186 aImgLst(BibResId( RID_TOOLBAR_IMGLIST )),
187 aBigImgLst(BibResId( RID_TOOLBAR_BIGIMGLIST )),
188 aFtSource(this,WB_VCENTER),
189 aLBSource(this,WB_DROPDOWN),
190 aFtQuery(this,WB_VCENTER),
191 aEdQuery(this),
192 nMenuId(0),
193 nSelMenuItem(0),
194 aLayoutManager( aLink ),
195 nSymbolsSize( SFX_SYMBOLS_SIZE_SMALL ),
196 nOutStyle( 0 )
198 SvtMiscOptions aSvtMiscOptions;
199 nSymbolsSize = aSvtMiscOptions.GetCurrentSymbolsSize();
200 nOutStyle = aSvtMiscOptions.GetToolboxStyle();
202 ApplyImageList();
203 SetStyle(GetStyle()|nStyle);
204 SetOutStyle(TOOLBOX_STYLE_FLAT);
205 Size a2Size(GetOutputSizePixel());
206 a2Size.Width()=100;
207 aLBSource.SetSizePixel(a2Size);
208 aLBSource.SetDropDownLineCount(9);
209 aLBSource.Show();
210 aLBSource.SetSelectHdl(LINK( this, BibToolBar, SelHdl));
212 SvtMiscOptions().AddListenerLink( LINK( this, BibToolBar, OptionsChanged_Impl ) );
213 Application::AddEventListener( LINK( this, BibToolBar, SettingsChanged_Impl ) );
215 aTimer.SetTimeoutHdl(LINK( this, BibToolBar, SendSelHdl));
216 aTimer.SetTimeout(400);
218 SetDropdownClickHdl( LINK( this, BibToolBar, MenuHdl));
220 aEdQuery.SetSizePixel(aLBSource.GetSizePixel());
221 aEdQuery.Show();
223 XubString aStr=GetItemText(TBC_FT_SOURCE);
224 Rectangle aRect=GetItemRect(TBC_FT_SOURCE);
225 aFtSource.SetText(aStr);
226 aFtSource.SetSizePixel(aRect.GetSize());
227 aFtSource.SetBackground(Wallpaper( COL_TRANSPARENT ));
229 aStr=GetItemText(TBC_FT_QUERY);
230 aRect=GetItemRect(TBC_FT_QUERY);
231 aFtQuery.SetText(aStr);
232 aFtQuery.SetSizePixel(aRect.GetSize());
233 aFtQuery.SetBackground(Wallpaper( COL_TRANSPARENT ));
235 SetItemWindow(TBC_FT_SOURCE,&aFtSource);
236 SetItemWindow(TBC_LB_SOURCE,&aLBSource);
237 SetItemWindow(TBC_FT_QUERY ,&aFtQuery);
238 SetItemWindow(TBC_ED_QUERY ,&aEdQuery);
240 ::bib::AddToTaskPaneList( this );
243 BibToolBar::~BibToolBar()
245 SvtMiscOptions().RemoveListenerLink( LINK( this, BibToolBar, OptionsChanged_Impl ) );
246 Application::RemoveEventListener( LINK( this, BibToolBar, SettingsChanged_Impl ) );
247 ::bib::RemoveFromTaskPaneList( this );
250 void BibToolBar::InitListener()
252 sal_uInt16 nCount=GetItemCount();
254 uno::Reference< frame::XDispatch > xDisp(xController,UNO_QUERY);
255 uno::Reference< util::XURLTransformer > xTrans( util::URLTransformer::create(comphelper::getProcessComponentContext()) );
256 if( xTrans.is() )
258 util::URL aQueryURL;
259 aQueryURL.Complete = C2U(".uno:Bib/MenuFilter");
260 xTrans->parseStrict( aQueryURL);
261 BibToolBarListener* pQuery=new BibTBQueryMenuListener(this,aQueryURL.Complete,TBC_BT_AUTOFILTER);
262 xDisp->addStatusListener(uno::Reference< frame::XStatusListener > (pQuery),aQueryURL);
264 for(sal_uInt16 nPos=0;nPos<nCount;nPos++)
266 sal_uInt16 nId=GetItemId(nPos);
267 if(!nId || nId==TBC_FT_SOURCE || nId==TBC_FT_QUERY)
268 continue;
270 util::URL aURL;
271 aURL.Complete = GetItemCommand(nId);
272 if(aURL.Complete.isEmpty())
273 continue;
275 xTrans->parseStrict( aURL );
277 BibToolBarListener* pListener=NULL;
278 if(nId==TBC_LB_SOURCE)
280 pListener=new BibTBListBoxListener(this,aURL.Complete,nId);
282 else if(nId==TBC_ED_QUERY)
284 pListener=new BibTBEditListener(this,aURL.Complete,nId);
286 else
288 pListener=new BibToolBarListener(this,aURL.Complete,nId);
291 BibToolBarListenerRef* pxInsert = new Reference<frame::XStatusListener>;
292 (*pxInsert) = pListener;
293 aListenerArr.push_back( pxInsert );
294 xDisp->addStatusListener(uno::Reference< frame::XStatusListener > (pListener),aURL);
299 void BibToolBar::SetXController(const uno::Reference< frame::XController > & xCtr)
301 xController=xCtr;
302 InitListener();
306 void BibToolBar::Select()
308 sal_uInt16 nId=GetCurItemId();
310 if(nId!=TBC_BT_AUTOFILTER)
312 SendDispatch(nId,Sequence<PropertyValue>() );
314 else
316 Sequence<PropertyValue> aPropVal(2);
317 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
318 pPropertyVal[0].Name=C2U("QueryText");
319 rtl::OUString aSelection = aEdQuery.GetText();
320 pPropertyVal[0].Value <<= aSelection;
322 pPropertyVal[1].Name=C2U("QueryField");
323 pPropertyVal[1].Value <<= aQueryField;
324 SendDispatch(nId,aPropVal);
328 void BibToolBar::SendDispatch(sal_uInt16 nId, const Sequence< PropertyValue >& rArgs)
330 rtl::OUString aCommand = GetItemCommand(nId);
332 uno::Reference< frame::XDispatchProvider > xDSP( xController, UNO_QUERY );
334 if( xDSP.is() && !aCommand.isEmpty())
336 uno::Reference< util::XURLTransformer > xTrans( util::URLTransformer::create(comphelper::getProcessComponentContext()) );
337 if( xTrans.is() )
339 // Datei laden
340 util::URL aURL;
341 aURL.Complete = aCommand;
343 xTrans->parseStrict( aURL );
345 uno::Reference< frame::XDispatch > xDisp = xDSP->queryDispatch( aURL, rtl::OUString(), frame::FrameSearchFlag::SELF );
347 if ( xDisp.is() )
348 xDisp->dispatch( aURL, rArgs);
354 void BibToolBar::Click()
356 sal_uInt16 nId=GetCurItemId();
358 if(nId == TBC_BT_COL_ASSIGN )
360 if(pDatMan)
361 pDatMan->CreateMappingDialog(GetParent());
362 CheckItem( nId, sal_False );
364 else if(nId == TBC_BT_CHANGESOURCE)
366 if(pDatMan)
368 OUString sNew = pDatMan->CreateDBChangeDialog(GetParent());
369 if(!sNew.isEmpty())
370 pDatMan->setActiveDataSource(sNew);
372 CheckItem( nId, sal_False );
376 void BibToolBar::ClearFilterMenu()
378 aPopupMenu.Clear();
379 nMenuId=0;
381 sal_uInt16 BibToolBar::InsertFilterItem(const XubString& aMenuEntry)
383 nMenuId++;
384 aPopupMenu.InsertItem(nMenuId,aMenuEntry);
386 return nMenuId;
388 void BibToolBar::SelectFilterItem(sal_uInt16 nId)
390 aPopupMenu.CheckItem(nId);
391 nSelMenuItem=nId;
392 aQueryField = MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu.GetItemText(nId) );
395 void BibToolBar::EnableSourceList(sal_Bool bFlag)
397 aFtSource.Enable(bFlag);
398 aLBSource.Enable(bFlag);
401 void BibToolBar::ClearSourceList()
403 aLBSource.Clear();
406 void BibToolBar::UpdateSourceList(sal_Bool bFlag)
408 aLBSource.SetUpdateMode(bFlag);
411 void BibToolBar::InsertSourceEntry(const XubString& aEntry, sal_uInt16 nPos)
413 aLBSource.InsertEntry(aEntry, nPos);
416 void BibToolBar::SelectSourceEntry(const XubString& aStr)
418 aLBSource.SelectEntry(aStr);
421 void BibToolBar::EnableQuery(sal_Bool bFlag)
423 aFtQuery.Enable(bFlag);
424 aEdQuery.Enable(bFlag);
427 void BibToolBar::SetQueryString(const XubString& aStr)
429 aEdQuery.SetText(aStr);
433 long BibToolBar::PreNotify( NotifyEvent& rNEvt )
435 long nResult=sal_True;
437 sal_uInt16 nSwitch=rNEvt.GetType();
438 if(aEdQuery.HasFocus() && nSwitch==EVENT_KEYINPUT)
440 const KeyCode& aKeyCode=rNEvt.GetKeyEvent()->GetKeyCode();
441 sal_uInt16 nKey = aKeyCode.GetCode();
442 if(nKey == KEY_RETURN)
444 Sequence<PropertyValue> aPropVal(2);
445 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
446 pPropertyVal[0].Name = C2U("QueryText");
447 rtl::OUString aSelection = aEdQuery.GetText();
448 pPropertyVal[0].Value <<= aSelection;
449 pPropertyVal[1].Name=C2U("QueryField");
450 pPropertyVal[1].Value <<= aQueryField;
451 SendDispatch(TBC_BT_AUTOFILTER,aPropVal);
452 return nResult;
457 nResult=ToolBox::PreNotify(rNEvt);
459 return nResult;
462 IMPL_LINK( BibToolBar, SelHdl, ListBox*, /*pLb*/ )
464 aTimer.Start();
465 return 0;
468 IMPL_LINK( BibToolBar, SendSelHdl, Timer*,/*pT*/)
470 Sequence<PropertyValue> aPropVal(1);
471 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
472 pPropertyVal[0].Name = C2U("DataSourceName");
473 String aEntry( MnemonicGenerator::EraseAllMnemonicChars( aLBSource.GetSelectEntry() ) );
474 rtl::OUString aSelection = aEntry;
475 pPropertyVal[0].Value <<= aSelection;
476 SendDispatch(TBC_LB_SOURCE,aPropVal);
478 return 0;
480 //-----------------------------------------------------------------------------
481 IMPL_LINK( BibToolBar, MenuHdl, ToolBox*, /*pToolbox*/)
483 sal_uInt16 nId=GetCurItemId();
484 if(nId==TBC_BT_AUTOFILTER)
486 EndSelection(); // vor SetDropMode (SetDropMode ruft SetItemImage)
488 SetItemDown(TBC_BT_AUTOFILTER,sal_True);
489 nId = aPopupMenu.Execute(this, GetItemRect(TBC_BT_AUTOFILTER));
492 if(nId>0)
494 aPopupMenu.CheckItem(nSelMenuItem,sal_False);
495 aPopupMenu.CheckItem(nId);
496 nSelMenuItem=nId;
497 aQueryField = MnemonicGenerator::EraseAllMnemonicChars( aPopupMenu.GetItemText(nId) );
498 Sequence<PropertyValue> aPropVal(2);
499 PropertyValue* pPropertyVal = (PropertyValue*)aPropVal.getConstArray();
500 pPropertyVal[0].Name = C2U("QueryText");
501 rtl::OUString aSelection = aEdQuery.GetText();
502 pPropertyVal[0].Value <<= aSelection;
503 pPropertyVal[1].Name=C2U("QueryField");
504 pPropertyVal[1].Value <<= aQueryField;
505 SendDispatch(TBC_BT_AUTOFILTER,aPropVal);
508 Point aPoint;
509 MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
510 MouseMove( aLeave );
511 SetItemDown(TBC_BT_AUTOFILTER,sal_False);
515 return 0;
517 //-----------------------------------------------------------------------------
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() == DATACHANGED_SETTINGS) &&
531 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
532 ApplyImageList();
533 ToolBox::DataChanged( rDCEvt );
536 IMPL_LINK( BibToolBar, OptionsChanged_Impl, void*, /*pVoid*/ )
538 sal_Bool bRebuildToolBar = sal_False;
539 sal_Int16 eSymbolsSize = SvtMiscOptions().GetCurrentSymbolsSize();
540 if ( nSymbolsSize != eSymbolsSize )
542 nSymbolsSize = eSymbolsSize;
543 bRebuildToolBar = sal_True;
545 else if ( nOutStyle != SvtMiscOptions().GetToolboxStyle() )
547 nOutStyle = SvtMiscOptions().GetToolboxStyle();
548 SetOutStyle( nOutStyle );
549 bRebuildToolBar = sal_True;
552 if ( bRebuildToolBar )
553 RebuildToolbar();
555 return 0L;
558 //-----------------------------------------------------------------------------
560 IMPL_LINK( BibToolBar, SettingsChanged_Impl, void*, /*pVoid*/ )
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;
567 RebuildToolbar();
570 return 0L;
573 //-----------------------------------------------------------------------------
574 void BibToolBar::RebuildToolbar()
576 ApplyImageList();
577 // We have to call parent asynchronously as SetSize works also asynchronously!
578 Application::PostUserEvent( aLayoutManager, 0 );
581 //-----------------------------------------------------------------------------
583 void BibToolBar::ApplyImageList()
585 ImageList& rList = ( nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ) ?
586 ( aImgLst ) :
587 ( aBigImgLst );
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 ));
592 AdjustToolBox();
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();
605 if (
606 (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
607 (aSize.Height() && aSize.Height() != aTbSize.Height())
610 SetPosSizePixel( GetPosPixel(), aSize );
611 Invalidate();
615 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */