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