1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "precompiled_reportdesign.hxx"
24 #include "AddField.hxx"
25 #include "UITools.hxx"
26 #include <svx/dbaexchange.hxx>
27 #include <svx/svdpagv.hxx>
28 #include <com/sun/star/sdb/CommandType.hpp>
29 #include <com/sun/star/util/URL.hpp>
30 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
31 #include <com/sun/star/util/URL.hpp>
32 #include <com/sun/star/i18n/XCollator.hpp>
33 
34 #include <vcl/waitobj.hxx>
35 #include <vcl/svapp.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <comphelper/stl_types.hxx>
38 #include "rptui_slotid.hrc"
39 
40 #include <connectivity/dbtools.hxx>
41 #include "helpids.hrc"
42 #include "RptResId.hrc"
43 #include "CondFormat.hrc"
44 #include "ModuleHelper.hxx"
45 #include "uistrings.hrc"
46 #include "ColumnInfo.hxx"
47 
48 #include <comphelper/property.hxx>
49 #include <svtools/imgdef.hxx>
50 
51 namespace rptui
52 {
53 const long STD_WIN_SIZE_X = 180;
54 const long STD_WIN_SIZE_Y = 320;
55 
56 const long LISTBOX_BORDER = 2;
57 
58 using namespace ::com::sun::star;
59 using namespace sdbc;
60 using namespace sdb;
61 using namespace uno;
62 using namespace datatransfer;
63 using namespace beans;
64 using namespace lang;
65 using namespace container;
66 using namespace ::svx;
67 
68 class OAddFieldWindowListBox	: public SvTreeListBox
69 {
70 	OAddFieldWindow*                    m_pTabWin;
71 
72     OAddFieldWindowListBox(const OAddFieldWindowListBox&);
73     void operator =(const OAddFieldWindowListBox&);
74 protected:
75 //	virtual void Command( const CommandEvent& rEvt );
76 
77 public:
78 	OAddFieldWindowListBox( OAddFieldWindow* _pParent );
79 	virtual ~OAddFieldWindowListBox();
80 
81 	sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
82 	sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
83 
84     uno::Sequence< beans::PropertyValue > getSelectedFieldDescriptors();
85 
86 protected:
87 	// DragSourceHelper
88 	virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel );
89 
90 private:
91     using SvTreeListBox::ExecuteDrop;
92 };
93 // -----------------------------------------------------------------------------
getSelectedFieldDescriptors()94 uno::Sequence< beans::PropertyValue > OAddFieldWindowListBox::getSelectedFieldDescriptors()
95 {
96     uno::Sequence< beans::PropertyValue > aArgs(GetSelectionCount());
97     sal_Int32 i = 0;
98 	SvLBoxEntry* pSelected = FirstSelected();
99 	while( pSelected )
100 	{
101 		// build a descriptor for the currently selected field
102         ::svx::ODataAccessDescriptor aDescriptor;
103         m_pTabWin->fillDescriptor(pSelected,aDescriptor);
104         aArgs[i++].Value <<= aDescriptor.createPropertyValueSequence();
105         pSelected = NextSelected(pSelected);
106 	}
107     return aArgs;
108 }
109 //==================================================================
110 // class OAddFieldWindowListBox
111 //==================================================================
112 DBG_NAME( rpt_OAddFieldWindowListBox );
113 //------------------------------------------------------------------------------
OAddFieldWindowListBox(OAddFieldWindow * _pParent)114 OAddFieldWindowListBox::OAddFieldWindowListBox( OAddFieldWindow* _pParent )
115 	:SvTreeListBox( _pParent, WB_TABSTOP|WB_BORDER|WB_SORT )
116 	,m_pTabWin( _pParent )
117 {
118 	DBG_CTOR( rpt_OAddFieldWindowListBox,NULL);
119 	SetHelpId( HID_RPT_FIELD_SEL );
120     SetSelectionMode(MULTIPLE_SELECTION);
121     SetDragDropMode( 0xFFFF );
122 	SetHighlightRange( );
123 }
124 
125 //------------------------------------------------------------------------------
~OAddFieldWindowListBox()126 OAddFieldWindowListBox::~OAddFieldWindowListBox()
127 {
128 	DBG_DTOR( rpt_OAddFieldWindowListBox,NULL);
129 }
130 
131 //------------------------------------------------------------------------------
AcceptDrop(const AcceptDropEvent &)132 sal_Int8 OAddFieldWindowListBox::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
133 {
134 	return DND_ACTION_NONE;
135 }
136 
137 //------------------------------------------------------------------------------
ExecuteDrop(const ExecuteDropEvent &)138 sal_Int8 OAddFieldWindowListBox::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
139 {
140 	return DND_ACTION_NONE;
141 }
142 
143 //------------------------------------------------------------------------------
StartDrag(sal_Int8,const Point &)144 void OAddFieldWindowListBox::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
145 {
146 	if ( GetSelectionCount() < 1 )
147 		// no drag without a field
148 		return;
149 
150     OMultiColumnTransferable* pDataContainer = new OMultiColumnTransferable(getSelectedFieldDescriptors());
151     Reference< XTransferable> xEnsureDelete = pDataContainer;
152 
153 	EndSelection();
154 	pDataContainer->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
155 }
156 //========================================================================
157 // class OAddFieldWindow
158 //========================================================================
159 DBG_NAME( rpt_OAddFieldWindow );
160 //-----------------------------------------------------------------------
OAddFieldWindow(Window * pParent,const uno::Reference<beans::XPropertySet> & _xRowSet)161 OAddFieldWindow::OAddFieldWindow(Window* pParent
162                                  ,const uno::Reference< beans::XPropertySet >& _xRowSet
163                                  )
164 			:FloatingWindow(pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE))
165 			,::comphelper::OPropertyChangeListener(m_aMutex)
166             ,::comphelper::OContainerListener(m_aMutex)
167             ,m_xRowSet(_xRowSet)
168             ,m_aActions(this,ModuleRes(RID_TB_SORTING))
169             ,m_pListBox(new OAddFieldWindowListBox( this ))
170             ,m_aFixedLine(this, ModuleRes(ADDFIELD_FL_HELP_SEPARATOR) )
171             ,m_aHelpText(this, ModuleRes(ADDFIELD_HELP_FIELD) )
172             ,m_aInsertButton(this, WB_TABSTOP|WB_CENTER)
173 			,m_nCommandType(0)
174             ,m_bEscapeProcessing(sal_False)
175 			,m_pChangeListener(NULL)
176 			,m_pContainerListener(NULL)
177 {
178 	DBG_CTOR( rpt_OAddFieldWindow,NULL);
179 	SetHelpId( HID_RPT_FIELD_SEL_WIN );
180 	SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor()) );
181     SetMinOutputSizePixel(Size(STD_WIN_SIZE_X,STD_WIN_SIZE_Y));
182 
183     m_aActions.SetStyle(m_aActions.GetStyle()|WB_LINESPACING);
184     m_aActions.SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor()) );
185 
186     m_aActions.SetSelectHdl(LINK(this, OAddFieldWindow, OnSortAction));
187     setToolBox(&m_aActions);
188     m_aActions.CheckItem(SID_FM_SORTUP);
189     m_aActions.EnableItem(SID_ADD_CONTROL_PAIR, sal_False);
190 
191     m_pListBox->SetDoubleClickHdl(LINK( this, OAddFieldWindow, OnDoubleClickHdl ) );
192     m_pListBox->SetSelectHdl(LINK( this, OAddFieldWindow, OnSelectHdl ) );
193     m_pListBox->SetDeselectHdl(LINK( this, OAddFieldWindow, OnSelectHdl ) );
194     m_pListBox->SetDoubleClickHdl(LINK( this, OAddFieldWindow, OnDoubleClickHdl ) );
195 	m_pListBox->Show();
196     const String sTitle(ModuleRes(RID_STR_INSERT));
197     m_aInsertButton.SetText(sTitle);
198     m_aInsertButton.SetClickHdl(LINK( this, OAddFieldWindow, OnDoubleClickHdl ) );
199     m_aInsertButton.Show();
200 
201     m_aFixedLine.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
202     m_aHelpText.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
203 
204     SetSizePixel(Size(STD_WIN_SIZE_X,STD_WIN_SIZE_Y));
205     //Show();
206 
207     if ( m_xRowSet.is() )
208     {
209         try
210         {
211             // be notified when the settings of report definition change
212 	        m_pChangeListener = new ::comphelper::OPropertyChangeMultiplexer( this, m_xRowSet );
213 	        m_pChangeListener->addProperty( PROPERTY_COMMAND );
214 	        m_pChangeListener->addProperty( PROPERTY_COMMANDTYPE );
215 	        m_pChangeListener->addProperty( PROPERTY_ESCAPEPROCESSING );
216 	        m_pChangeListener->addProperty( PROPERTY_FILTER );
217         }
218         catch( const Exception& )
219         {
220     	    DBG_UNHANDLED_EXCEPTION();
221         }
222     }
223 }
224 
225 //-----------------------------------------------------------------------
~OAddFieldWindow()226 OAddFieldWindow::~OAddFieldWindow()
227 {
228     if ( m_pListBox.get() )
229     {
230         SvLBoxTreeList*	pModel = m_pListBox->GetModel();
231         sal_uLong nCount = pModel->GetEntryCount();
232         for(sal_uLong i = 0; i< nCount;++i)
233         {
234             delete static_cast<ColumnInfo*>(pModel->GetEntry(i)->GetUserData());
235         }
236     }
237 	if (m_pChangeListener.is())
238 		m_pChangeListener->dispose();
239     if ( m_pContainerListener.is() )
240         m_pContainerListener->dispose();
241 	DBG_DTOR( rpt_OAddFieldWindow,NULL);
242 }
243 
244 //-----------------------------------------------------------------------
GetFocus()245 void OAddFieldWindow::GetFocus()
246 {
247 	if ( m_pListBox.get() )
248 		m_pListBox->GrabFocus();
249 	else
250 		FloatingWindow::GetFocus();
251 }
252 //-----------------------------------------------------------------------
getSelectedFieldDescriptors()253 uno::Sequence< beans::PropertyValue > OAddFieldWindow::getSelectedFieldDescriptors()
254 {
255     return m_pListBox->getSelectedFieldDescriptors();
256 }
257 
258 //-----------------------------------------------------------------------
PreNotify(NotifyEvent & _rNEvt)259 long OAddFieldWindow::PreNotify( NotifyEvent& _rNEvt )
260 {
261 	if ( EVENT_KEYINPUT == _rNEvt.GetType() )
262 	{
263 		const KeyCode& rKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode();
264 		if ( ( 0 == rKeyCode.GetModifier() ) && ( KEY_RETURN == rKeyCode.GetCode() ) )
265 		{
266 			if ( m_aCreateLink.IsSet() )
267             {
268                 m_aCreateLink.Call(this);
269 				return 1;
270             }
271 		}
272 	}
273 
274 	return FloatingWindow::PreNotify( _rNEvt );
275 }
276 //-----------------------------------------------------------------------
_propertyChanged(const beans::PropertyChangeEvent & _evt)277 void OAddFieldWindow::_propertyChanged( const beans::PropertyChangeEvent& _evt ) throw( uno::RuntimeException )
278 {
279     OSL_ENSURE( _evt.Source == m_xRowSet, "OAddFieldWindow::_propertyChanged: where did this come from?" );
280 	(void)_evt;
281 	Update();
282 }
283 
284 //-----------------------------------------------------------------------
285 namespace
286 {
lcl_addToList(OAddFieldWindowListBox & _rListBox,const uno::Sequence<::rtl::OUString> & _rEntries)287     void lcl_addToList( OAddFieldWindowListBox& _rListBox, const uno::Sequence< ::rtl::OUString >& _rEntries )
288     {
289 		const ::rtl::OUString* pEntries = _rEntries.getConstArray();
290 		sal_Int32 nEntries = _rEntries.getLength();
291 		for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
292 			_rListBox.InsertEntry( *pEntries,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries) );
293     }
lcl_addToList(OAddFieldWindowListBox & _rListBox,const uno::Reference<container::XNameAccess> & i_xColumns)294     void lcl_addToList( OAddFieldWindowListBox& _rListBox, const uno::Reference< container::XNameAccess>& i_xColumns )
295     {
296         uno::Sequence< ::rtl::OUString > aEntries = i_xColumns->getElementNames();
297 		const ::rtl::OUString* pEntries = aEntries.getConstArray();
298 		sal_Int32 nEntries = aEntries.getLength();
299 		for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
300         {
301             uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(*pEntries),UNO_QUERY_THROW);
302             ::rtl::OUString sLabel;
303             if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
304                 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
305             if ( sLabel.getLength() )
306 			    _rListBox.InsertEntry( sLabel,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries,sLabel) );
307             else
308                 _rListBox.InsertEntry( *pEntries,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries,sLabel) );
309         }
310     }
311 }
312 
313 //-----------------------------------------------------------------------
Update()314 void OAddFieldWindow::Update()
315 {
316     if ( m_pContainerListener.is() )
317         m_pContainerListener->dispose();
318     m_pContainerListener = NULL;
319     m_xColumns.clear();
320 
321     try
322     {
323         // ListBox loeschen
324 	    m_pListBox->Clear();
325         const sal_uInt16 nItemCount = m_aActions.GetItemCount();
326         for (sal_uInt16 j = 0; j< nItemCount; ++j)
327         {
328             m_aActions.EnableItem(m_aActions.GetItemId(j),sal_False);
329         }
330 
331 	    String aTitle(ModuleRes(RID_STR_FIELDSELECTION));
332 	    SetText(aTitle);
333         if ( m_xRowSet.is() )
334         {
335             ::rtl::OUString sCommand( m_aCommandName );
336             sal_Int32       nCommandType( m_nCommandType );
337             sal_Bool        bEscapeProcessing( m_bEscapeProcessing );
338             ::rtl::OUString sFilter( m_sFilter );
339 
340             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
341             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nCommandType );
342             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_ESCAPEPROCESSING ) >>= bEscapeProcessing );
343             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_FILTER ) >>= sFilter );
344 
345 	        m_aCommandName	= sCommand;
346 	        m_nCommandType 	= nCommandType;
347             m_bEscapeProcessing = bEscapeProcessing;
348             m_sFilter = sFilter;
349 
350             // add the columns to the list
351             uno::Reference< sdbc::XConnection> xCon = getConnection();
352 	        if ( xCon.is() && m_aCommandName.getLength() )
353 			    m_xColumns = dbtools::getFieldsByCommandDescriptor( xCon, GetCommandType(), GetCommand(), m_xHoldAlive );
354             if ( m_xColumns.is() )
355             {
356                 lcl_addToList( *m_pListBox, m_xColumns );
357                 uno::Reference< container::XContainer> xContainer(m_xColumns,uno::UNO_QUERY);
358                 if ( xContainer.is() )
359                     m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer);
360             }
361 
362             // add the parameter columns to the list
363             uno::Reference< ::com::sun::star::sdbc::XRowSet > xRowSet(m_xRowSet,uno::UNO_QUERY);
364             Sequence< ::rtl::OUString > aParamNames( getParameterNames( xRowSet ) );
365             lcl_addToList( *m_pListBox, aParamNames );
366 
367             // set title
368 	        aTitle.AppendAscii(" ");
369 	        aTitle += m_aCommandName.getStr();
370 	        SetText( aTitle );
371             if ( m_aCommandName.getLength() )
372             {
373                 for (sal_uInt16 i = 0; i < nItemCount; ++i)
374                 {
375                     m_aActions.EnableItem(m_aActions.GetItemId(i));
376                 }
377             }
378                 OnSelectHdl(NULL);
379         }
380     }
381     catch( const Exception& )
382     {
383         DBG_UNHANDLED_EXCEPTION();
384     }
385 }
386 
387 //-----------------------------------------------------------------------
Resize()388 void OAddFieldWindow::Resize()
389 {
390 	FloatingWindow::Resize();
391 
392 	const Size aWindowSize( GetOutputSizePixel() );
393 
394 
395     const Size aRelated(LogicToPixel( Size( RELATED_CONTROLS, RELATED_CONTROLS ), MAP_APPFONT ));
396     const Size aFixedTextSize(LogicToPixel( Size( FIXEDTEXT_WIDTH, FIXEDTEXT_HEIGHT ), MAP_APPFONT ));
397 
398     // ToolBar
399     Size aToolbarSize( m_aActions.GetSizePixel() );
400     Point aToolbarPos( aRelated.Width(), aRelated.Height());
401     m_aActions.SetPosPixel(Point(aToolbarPos.X(), aToolbarPos.Y()));
402 
403     Size aLBSize( aWindowSize );
404 	aLBSize.Width()  -= ( 2 * aRelated.Width() );
405 
406     // help text
407     const Size aHelpTextSize = m_aHelpText.CalcMinimumSize(aLBSize.Width());
408 
409     // ListBox
410 	Point aLBPos( aRelated.Width(), aRelated.Height() + aToolbarSize.Height() + aRelated.Height() );
411 
412 	aLBSize.Height() -= aToolbarSize.Height();   //         Toolbar
413 	aLBSize.Height() -= (6*aRelated.Height());   //         6 * gap
414     aLBSize.Height() -= aFixedTextSize.Height(); //         fixed line
415     aLBSize.Height() -= aHelpTextSize.Height();  //         help text
416 	m_pListBox->SetPosSizePixel( aLBPos, aLBSize );
417 
418     // FixedLine
419 	Size aFLSize( aLBSize.Width(),aFixedTextSize.Height() );
420     Point aFLPos( aRelated.Width(), aLBPos.Y() + aLBSize.Height() + aRelated.Height());
421     m_aFixedLine.SetPosSizePixel( aFLPos, aFLSize );
422 
423     // Help text
424     Point aFTPos( aRelated.Width(), aFLPos.Y() + aFLSize.Height() + aRelated.Height() );
425     m_aHelpText.SetPosSizePixel( aFTPos, aHelpTextSize );
426 }
427 // -----------------------------------------------------------------------------
getConnection() const428 uno::Reference< sdbc::XConnection> OAddFieldWindow::getConnection() const
429 {
430     return uno::Reference< sdbc::XConnection>(m_xRowSet->getPropertyValue( PROPERTY_ACTIVECONNECTION ),uno::UNO_QUERY);
431 }
432 // -----------------------------------------------------------------------------
fillDescriptor(SvLBoxEntry * _pSelected,::svx::ODataAccessDescriptor & _rDescriptor)433 void OAddFieldWindow::fillDescriptor(SvLBoxEntry* _pSelected,::svx::ODataAccessDescriptor& _rDescriptor)
434 {
435     if ( _pSelected && m_xColumns.is() )
436     {
437         uno::Reference<container::XChild> xChild(getConnection(),uno::UNO_QUERY);
438         if ( xChild.is( ) )
439         {
440             uno::Reference<sdb::XDocumentDataSource> xDocument( xChild->getParent(), uno::UNO_QUERY );
441             if ( xDocument.is() )
442             {
443                 uno::Reference<frame::XModel> xModel(xDocument->getDatabaseDocument(),uno::UNO_QUERY);
444                 if ( xModel.is() )
445                     _rDescriptor[ daDatabaseLocation ] <<= xModel->getURL();
446             } // if ( xDocument.is() )
447         }
448 
449         _rDescriptor[ ::svx::daCommand ]            <<= GetCommand();
450         _rDescriptor[ ::svx::daCommandType ]        <<= GetCommandType();
451         _rDescriptor[ ::svx::daEscapeProcessing ]   <<= GetEscapeProcessing();
452         _rDescriptor[ ::svx::daConnection ]         <<= getConnection();
453 
454         ColumnInfo* pInfo = static_cast<ColumnInfo*>(_pSelected->GetUserData());
455         // ::rtl::OUString sColumnName = m_pListBox->GetEntryText( _pSelected );
456         _rDescriptor[ ::svx::daColumnName ]         <<= pInfo->sColumnName;
457         if ( m_xColumns->hasByName( pInfo->sColumnName ) )
458             _rDescriptor[ ::svx::daColumnObject ] <<= m_xColumns->getByName(pInfo->sColumnName);
459     }
460 }
461 // -----------------------------------------------------------------------------
_elementInserted(const container::ContainerEvent & _rEvent)462 void OAddFieldWindow::_elementInserted( const container::ContainerEvent& _rEvent )  throw(::com::sun::star::uno::RuntimeException)
463 {
464     if ( m_pListBox.get() )
465     {
466         ::rtl::OUString sName;
467         if ( (_rEvent.Accessor >>= sName) && m_xColumns->hasByName(sName) )
468         {
469             uno::Reference< beans::XPropertySet> xColumn(m_xColumns->getByName(sName),UNO_QUERY_THROW);
470             ::rtl::OUString sLabel;
471             if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
472                 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
473             if ( sLabel.getLength() )
474 			    m_pListBox->InsertEntry( sLabel,NULL,sal_False,LIST_APPEND,new ColumnInfo(sName,sLabel) );
475             else
476                 m_pListBox->InsertEntry( sName,NULL,sal_False,LIST_APPEND,new ColumnInfo(sName,sLabel) );
477         }
478     }
479 }
480 // -----------------------------------------------------------------------------
_elementRemoved(const container::ContainerEvent &)481 void OAddFieldWindow::_elementRemoved( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
482 {
483     if ( m_pListBox.get() )
484     {
485         m_pListBox->Clear();
486         if ( m_xColumns.is() )
487             lcl_addToList( *m_pListBox, m_xColumns );
488     }
489 }
490 // -----------------------------------------------------------------------------
_elementReplaced(const container::ContainerEvent &)491 void OAddFieldWindow::_elementReplaced( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
492 {
493 }
494 // -----------------------------------------------------------------------------
495 IMPL_LINK( OAddFieldWindow, OnSelectHdl, void* ,/*_pAddFieldDlg*/)
496 {
497     m_aActions.EnableItem(SID_ADD_CONTROL_PAIR, ( m_pListBox.get() && m_pListBox->GetSelectionCount() > 0 ));
498 
499     return 0L;
500 }
501 // -----------------------------------------------------------------------------
502 IMPL_LINK( OAddFieldWindow, OnDoubleClickHdl, void* ,/*_pAddFieldDlg*/)
503 {
504     if ( m_aCreateLink.IsSet() )
505         m_aCreateLink.Call(this);
506 
507     return 0L;
508 }
509 //------------------------------------------------------------------------------
getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const510 ImageList OAddFieldWindow::getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
511 {
512     sal_Int16 nN = IMG_ADDFIELD_DLG_SC;
513     sal_Int16 nH = IMG_ADDFIELD_DLG_SCH;
514     if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
515     {
516         nN = IMG_ADDFIELD_DLG_LC;
517         nH = IMG_ADDFIELD_DLG_LCH;
518     }
519     return ImageList(ModuleRes( _bHiContast ? nH : nN ));
520 }
521 //------------------------------------------------------------------
resizeControls(const Size & _rDiff)522 void OAddFieldWindow::resizeControls(const Size& _rDiff)
523 {
524     // we use large images so we must change them
525     if ( _rDiff.Width() || _rDiff.Height() )
526     {
527         Invalidate();
528     }
529 }
530 //------------------------------------------------------------------
531 IMPL_LINK( OAddFieldWindow, OnSortAction, ToolBox*, /*NOTINTERESTEDIN*/ )
532 {
533     const sal_uInt16 nCurItem = m_aActions.GetCurItemId();
534     if ( SID_ADD_CONTROL_PAIR == nCurItem )
535         OnDoubleClickHdl(NULL);
536     else
537     {
538         if ( SID_FM_REMOVE_FILTER_SORT == nCurItem || !m_aActions.IsItemChecked(nCurItem) )
539         {
540             const sal_uInt16 nItemCount = m_aActions.GetItemCount();
541             for (sal_uInt16 j = 0; j< nItemCount; ++j)
542             {
543                 const sal_uInt16 nItemId = m_aActions.GetItemId(j);
544                 if ( nCurItem != nItemId )
545                     m_aActions.CheckItem(nItemId,sal_False);
546             }
547             SvSortMode eSortMode = SortNone;
548             if ( SID_FM_REMOVE_FILTER_SORT != nCurItem )
549             {
550                 m_aActions.CheckItem(nCurItem,!m_aActions.IsItemChecked(nCurItem));
551                 if ( m_aActions.IsItemChecked(SID_FM_SORTUP) )
552                     eSortMode = SortAscending;
553                 else if ( m_aActions.IsItemChecked(SID_FM_SORTDOWN) )
554                     eSortMode = SortDescending;
555             } // if ( SID_FM_REMOVE_FILTER_SORT != nCurItem )
556 
557             m_pListBox->GetModel()->SetSortMode(eSortMode);
558             if ( SID_FM_REMOVE_FILTER_SORT == nCurItem )
559                 Update();
560 
561             m_pListBox->GetModel()->Resort();
562         }
563     }
564     return 0L;
565 }
566 // -----------------------------------------------------------------------------
567 // =============================================================================
568 } // namespace rptui
569 // =============================================================================
570 
571