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