xref: /aoo41x/main/svx/source/form/tabwin.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "tabwin.hxx"
28cdf0e10cSrcweir #include "svx/fmtools.hxx"
29cdf0e10cSrcweir #include "fmservs.hxx"
30cdf0e10cSrcweir #include "stringlistresource.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <svx/svxids.hrc>
33cdf0e10cSrcweir #include <svx/dbaexchange.hxx>
34cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
35cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
37cdf0e10cSrcweir #include <com/sun/star/sdbc/XPreparedStatement.hpp>
38cdf0e10cSrcweir #include <com/sun/star/awt/XControlContainer.hpp>
39cdf0e10cSrcweir #include <com/sun/star/util/XLocalizedAliases.hpp>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #ifndef _SVX_FMHELP_HRC
44cdf0e10cSrcweir #include "fmhelp.hrc"
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #include <svx/fmshell.hxx>
47cdf0e10cSrcweir #include "fmshimp.hxx"
48cdf0e10cSrcweir #include "svx/dbtoolsclient.hxx"
49cdf0e10cSrcweir #include <svx/fmpage.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #ifndef _SVX_FMPGEIMP_HXX
52cdf0e10cSrcweir #include "fmpgeimp.hxx"
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
56cdf0e10cSrcweir #include "fmprop.hrc"
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #ifndef _SVX_FMRESIDS_HRC
60cdf0e10cSrcweir #include "svx/fmresids.hrc"
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #include <svx/dialmgr.hxx>
63cdf0e10cSrcweir #include <tools/shl.hxx>
64cdf0e10cSrcweir #include <svx/svdpagv.hxx>
65cdf0e10cSrcweir #include <sfx2/objitem.hxx>
66cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
67cdf0e10cSrcweir #include <comphelper/property.hxx>
68cdf0e10cSrcweir #include <sfx2/frame.hxx>
69cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir const long STD_WIN_POS_X = 50;
72cdf0e10cSrcweir const long STD_WIN_POS_Y = 50;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir const long STD_WIN_SIZE_X = 120;
75cdf0e10cSrcweir const long STD_WIN_SIZE_Y = 150;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir const long MIN_WIN_SIZE_X = 50;
78cdf0e10cSrcweir const long MIN_WIN_SIZE_Y = 50;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir const long LISTBOX_BORDER = 2;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
83cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
84cdf0e10cSrcweir using namespace ::com::sun::star::uno;
85cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
86cdf0e10cSrcweir using namespace ::com::sun::star::beans;
87cdf0e10cSrcweir using namespace ::com::sun::star::lang;
88cdf0e10cSrcweir using namespace ::com::sun::star::form;
89cdf0e10cSrcweir using namespace ::com::sun::star::container;
90cdf0e10cSrcweir using namespace ::com::sun::star;
91cdf0e10cSrcweir using namespace ::svxform;
92cdf0e10cSrcweir using namespace ::svx;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir struct ColumnInfo
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     ::rtl::OUString sColumnName;
98cdf0e10cSrcweir     ::rtl::OUString sLabel;
99cdf0e10cSrcweir     bool bColumn;
ColumnInfoColumnInfo100cdf0e10cSrcweir     ColumnInfo(const ::rtl::OUString& i_sColumnName,const ::rtl::OUString& i_sLabel)
101cdf0e10cSrcweir         : sColumnName(i_sColumnName)
102cdf0e10cSrcweir         , sLabel(i_sLabel)
103cdf0e10cSrcweir         , bColumn(true)
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir     }
ColumnInfoColumnInfo106cdf0e10cSrcweir     ColumnInfo(const ::rtl::OUString& i_sColumnName)
107cdf0e10cSrcweir         : sColumnName(i_sColumnName)
108cdf0e10cSrcweir         , bColumn(false)
109cdf0e10cSrcweir     {
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir };
112cdf0e10cSrcweir 
lcl_addToList(SvTreeListBox & _rListBox,const uno::Reference<container::XNameAccess> & i_xColumns)113cdf0e10cSrcweir void lcl_addToList( SvTreeListBox& _rListBox, const uno::Reference< container::XNameAccess>& i_xColumns )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aEntries = i_xColumns->getElementNames();
116cdf0e10cSrcweir 	const ::rtl::OUString* pEntries = aEntries.getConstArray();
117cdf0e10cSrcweir 	sal_Int32 nEntries = aEntries.getLength();
118cdf0e10cSrcweir 	for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(*pEntries),UNO_QUERY_THROW);
121cdf0e10cSrcweir         ::rtl::OUString sLabel;
122cdf0e10cSrcweir         if ( xColumn->getPropertySetInfo()->hasPropertyByName(FM_PROP_LABEL) )
123cdf0e10cSrcweir             xColumn->getPropertyValue(FM_PROP_LABEL) >>= sLabel;
124cdf0e10cSrcweir         if ( sLabel.getLength() )
125cdf0e10cSrcweir 		    _rListBox.InsertEntry( sLabel,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries,sLabel) );
126cdf0e10cSrcweir         else
127cdf0e10cSrcweir             _rListBox.InsertEntry( *pEntries,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries,sLabel) );
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir }
130cdf0e10cSrcweir //==================================================================
131cdf0e10cSrcweir // class FmFieldWinListBox
132cdf0e10cSrcweir //==================================================================
DBG_NAME(FmFieldWinListBox)133cdf0e10cSrcweir DBG_NAME(FmFieldWinListBox)
134cdf0e10cSrcweir //------------------------------------------------------------------------------
135cdf0e10cSrcweir FmFieldWinListBox::FmFieldWinListBox( FmFieldWin* pParent )
136cdf0e10cSrcweir 	:SvTreeListBox( pParent, WB_HASBUTTONS|WB_BORDER )
137cdf0e10cSrcweir 	,pTabWin( pParent )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	DBG_CTOR(FmFieldWinListBox,NULL);
140cdf0e10cSrcweir 	SetHelpId( HID_FIELD_SEL );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	SetHighlightRange( );
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir //------------------------------------------------------------------------------
~FmFieldWinListBox()146cdf0e10cSrcweir FmFieldWinListBox::~FmFieldWinListBox()
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	DBG_DTOR(FmFieldWinListBox,NULL);
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir //------------------------------------------------------------------------------
AcceptDrop(const AcceptDropEvent &)152cdf0e10cSrcweir sal_Int8 FmFieldWinListBox::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	return DND_ACTION_NONE;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir //------------------------------------------------------------------------------
ExecuteDrop(const ExecuteDropEvent &)158cdf0e10cSrcweir sal_Int8 FmFieldWinListBox::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	return DND_ACTION_NONE;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //------------------------------------------------------------------------------
DoubleClickHdl()164cdf0e10cSrcweir sal_Bool FmFieldWinListBox::DoubleClickHdl()
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	if ( pTabWin->createSelectionControls() )
167cdf0e10cSrcweir 		return sal_True;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	return SvTreeListBox::DoubleClickHdl();
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir //------------------------------------------------------------------------------
StartDrag(sal_Int8,const Point &)173cdf0e10cSrcweir void FmFieldWinListBox::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	SvLBoxEntry* pSelected = FirstSelected();
176cdf0e10cSrcweir 	if (!pSelected)
177cdf0e10cSrcweir 		// no drag without a field
178cdf0e10cSrcweir 		return;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     ::svx::ODataAccessDescriptor aDescriptor;
181cdf0e10cSrcweir     aDescriptor[ daDataSource ] <<= pTabWin->GetDatabaseName();
182cdf0e10cSrcweir     aDescriptor[ daConnection ] <<= pTabWin->GetConnection().getTyped();
183cdf0e10cSrcweir     aDescriptor[ daCommand ]    <<= pTabWin->GetObjectName();
184cdf0e10cSrcweir     aDescriptor[ daCommandType ]<<= pTabWin->GetObjectType();
185cdf0e10cSrcweir     ColumnInfo* pInfo = static_cast<ColumnInfo*>(pSelected->GetUserData());
186cdf0e10cSrcweir 	aDescriptor[ daColumnName ]	<<= pInfo->sColumnName;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     TransferableHelper* pTransferColumn = new OColumnTransferable(
189cdf0e10cSrcweir 		aDescriptor, CTF_FIELD_DESCRIPTOR | CTF_CONTROL_EXCHANGE | CTF_COLUMN_DESCRIPTOR
190cdf0e10cSrcweir 	);
191cdf0e10cSrcweir 	Reference< XTransferable> xEnsureDelete = pTransferColumn;
192cdf0e10cSrcweir 	if (pTransferColumn)
193cdf0e10cSrcweir 	{
194cdf0e10cSrcweir 		EndSelection();
195cdf0e10cSrcweir 		pTransferColumn->StartDrag( this, DND_ACTION_COPY );
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir //========================================================================
200cdf0e10cSrcweir // class FmFieldWinData
201cdf0e10cSrcweir //========================================================================
202cdf0e10cSrcweir DBG_NAME(FmFieldWinData);
203cdf0e10cSrcweir //-----------------------------------------------------------------------
FmFieldWinData()204cdf0e10cSrcweir FmFieldWinData::FmFieldWinData()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir 	DBG_CTOR(FmFieldWinData,NULL);
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //-----------------------------------------------------------------------
~FmFieldWinData()210cdf0e10cSrcweir FmFieldWinData::~FmFieldWinData()
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	DBG_DTOR(FmFieldWinData,NULL);
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //========================================================================
216cdf0e10cSrcweir // class FmFieldWin
217cdf0e10cSrcweir //========================================================================
218cdf0e10cSrcweir DBG_NAME(FmFieldWin);
219cdf0e10cSrcweir //-----------------------------------------------------------------------
FmFieldWin(SfxBindings * _pBindings,SfxChildWindow * _pMgr,Window * _pParent)220cdf0e10cSrcweir FmFieldWin::FmFieldWin(SfxBindings* _pBindings, SfxChildWindow* _pMgr, Window* _pParent)
221cdf0e10cSrcweir 			:SfxFloatingWindow(_pBindings, _pMgr, _pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE))
222cdf0e10cSrcweir 			,SfxControllerItem(SID_FM_FIELDS_CONTROL, *_pBindings)
223cdf0e10cSrcweir 			,::comphelper::OPropertyChangeListener(m_aMutex)
224cdf0e10cSrcweir 			,pData(new FmFieldWinData)
225cdf0e10cSrcweir 			,m_nObjectType(0)
226cdf0e10cSrcweir 			,m_pChangeListener(NULL)
227cdf0e10cSrcweir {
228cdf0e10cSrcweir 	DBG_CTOR(FmFieldWin,NULL);
229cdf0e10cSrcweir 	SetHelpId( HID_FIELD_SEL_WIN );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor()) );
232cdf0e10cSrcweir 	pListBox = new FmFieldWinListBox( this );
233cdf0e10cSrcweir 	pListBox->Show();
234cdf0e10cSrcweir 	UpdateContent(NULL);
235cdf0e10cSrcweir 	SetSizePixel(Size(STD_WIN_SIZE_X,STD_WIN_SIZE_Y));
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir //-----------------------------------------------------------------------
~FmFieldWin()239cdf0e10cSrcweir FmFieldWin::~FmFieldWin()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	if (m_pChangeListener)
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		m_pChangeListener->dispose();
244cdf0e10cSrcweir 		m_pChangeListener->release();
245cdf0e10cSrcweir 		//	delete m_pChangeListener;
246cdf0e10cSrcweir 	}
247cdf0e10cSrcweir 	delete pListBox;
248cdf0e10cSrcweir 	delete pData;
249cdf0e10cSrcweir 	DBG_DTOR(FmFieldWin,NULL);
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir //-----------------------------------------------------------------------
GetFocus()253cdf0e10cSrcweir void FmFieldWin::GetFocus()
254cdf0e10cSrcweir {
255cdf0e10cSrcweir 	if ( pListBox )
256cdf0e10cSrcweir 		pListBox->GrabFocus();
257cdf0e10cSrcweir 	else
258cdf0e10cSrcweir 		SfxFloatingWindow::GetFocus();
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir //-----------------------------------------------------------------------
createSelectionControls()262cdf0e10cSrcweir sal_Bool FmFieldWin::createSelectionControls( )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	SvLBoxEntry* pSelected = pListBox->FirstSelected();
265cdf0e10cSrcweir 	if ( pSelected )
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir 		// build a descriptor for the currently selected field
268cdf0e10cSrcweir 		ODataAccessDescriptor aDescr;
269cdf0e10cSrcweir 		aDescr.setDataSource(GetDatabaseName());
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 		aDescr[ daConnection ]  <<= GetConnection().getTyped();
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         aDescr[ daCommand ]		<<= GetObjectName();
274cdf0e10cSrcweir 		aDescr[ daCommandType ]	<<= GetObjectType();
275cdf0e10cSrcweir         ColumnInfo* pInfo = static_cast<ColumnInfo*>(pSelected->GetUserData());
276cdf0e10cSrcweir 		aDescr[ daColumnName ]	<<= pInfo->sColumnName;//::rtl::OUString( pListBox->GetEntryText( pSelected) );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 		// transfer this to the SFX world
279cdf0e10cSrcweir 		SfxUnoAnyItem aDescriptorItem( SID_FM_DATACCESS_DESCRIPTOR, makeAny( aDescr.createPropertyValueSequence() ) );
280cdf0e10cSrcweir 		const SfxPoolItem* pArgs[] =
281cdf0e10cSrcweir 		{
282cdf0e10cSrcweir 			&aDescriptorItem, NULL
283cdf0e10cSrcweir 		};
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 		// execute the create slot
286cdf0e10cSrcweir 		GetBindings().Execute( SID_FM_CREATE_FIELDCONTROL, pArgs );
287cdf0e10cSrcweir 	}
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	return NULL != pSelected;
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir //-----------------------------------------------------------------------
PreNotify(NotifyEvent & _rNEvt)293cdf0e10cSrcweir long FmFieldWin::PreNotify( NotifyEvent& _rNEvt )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	if ( EVENT_KEYINPUT == _rNEvt.GetType() )
296cdf0e10cSrcweir 	{
297cdf0e10cSrcweir 		const KeyCode& rKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode();
298cdf0e10cSrcweir 		if ( ( 0 == rKeyCode.GetModifier() ) && ( KEY_RETURN == rKeyCode.GetCode() ) )
299cdf0e10cSrcweir 		{
300cdf0e10cSrcweir 			if ( createSelectionControls() )
301cdf0e10cSrcweir 				return 1;
302cdf0e10cSrcweir 		}
303cdf0e10cSrcweir 	}
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	return SfxFloatingWindow::PreNotify( _rNEvt );
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir //-----------------------------------------------------------------------
Close()309cdf0e10cSrcweir sal_Bool FmFieldWin::Close()
310cdf0e10cSrcweir {
311cdf0e10cSrcweir 	return SfxFloatingWindow::Close();
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir //-----------------------------------------------------------------------
_propertyChanged(const::com::sun::star::beans::PropertyChangeEvent & evt)315cdf0e10cSrcweir void FmFieldWin::_propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw( ::com::sun::star::uno::RuntimeException )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >  xForm(evt.Source, ::com::sun::star::uno::UNO_QUERY);
318cdf0e10cSrcweir 	UpdateContent(xForm);
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir //-----------------------------------------------------------------------
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)322cdf0e10cSrcweir void FmFieldWin::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
323cdf0e10cSrcweir {
324cdf0e10cSrcweir 	if (!pState  || SID_FM_FIELDS_CONTROL != nSID)
325cdf0e10cSrcweir 		return;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	if (eState >= SFX_ITEM_AVAILABLE)
328cdf0e10cSrcweir 	{
329cdf0e10cSrcweir 		FmFormShell* pShell = PTR_CAST(FmFormShell,((SfxObjectItem*)pState)->GetShell());
330cdf0e10cSrcweir 		UpdateContent(pShell);
331cdf0e10cSrcweir 	}
332cdf0e10cSrcweir 	else
333cdf0e10cSrcweir 		UpdateContent(NULL);
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir //-----------------------------------------------------------------------
UpdateContent(FmFormShell * pShell)337cdf0e10cSrcweir void FmFieldWin::UpdateContent(FmFormShell* pShell)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	pListBox->Clear();
340cdf0e10cSrcweir 	String aTitle( SVX_RES( RID_STR_FIELDSELECTION ) );
341cdf0e10cSrcweir 	SetText( aTitle );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 	if (!pShell || !pShell->GetImpl())
344cdf0e10cSrcweir 		return;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	Reference< XForm >  xForm = pShell->GetImpl()->getCurrentForm();
347cdf0e10cSrcweir 	if ( xForm.is() )
348cdf0e10cSrcweir 	    UpdateContent( xForm );
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir //-----------------------------------------------------------------------
UpdateContent(const::com::sun::star::uno::Reference<::com::sun::star::form::XForm> & xForm)352cdf0e10cSrcweir void FmFieldWin::UpdateContent(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm > & xForm)
353cdf0e10cSrcweir {
354cdf0e10cSrcweir     try
355cdf0e10cSrcweir     {
356cdf0e10cSrcweir         // ListBox loeschen
357cdf0e10cSrcweir 	    pListBox->Clear();
358cdf0e10cSrcweir 	    UniString aTitle(SVX_RES(RID_STR_FIELDSELECTION));
359cdf0e10cSrcweir 	    SetText(aTitle);
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 	    if (!xForm.is())
362cdf0e10cSrcweir 		    return;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	    Reference< XPreparedStatement >  xStatement;
365cdf0e10cSrcweir 	    Reference< XPropertySet >  xSet(xForm, UNO_QUERY);
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 	    m_aObjectName	= ::comphelper::getString(xSet->getPropertyValue(FM_PROP_COMMAND));
368cdf0e10cSrcweir 	    m_aDatabaseName	= ::comphelper::getString(xSet->getPropertyValue(FM_PROP_DATASOURCE));
369cdf0e10cSrcweir 	    m_nObjectType 	= ::comphelper::getINT32(xSet->getPropertyValue(FM_PROP_COMMANDTYPE));
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 	    // get the connection of the form
372cdf0e10cSrcweir         OStaticDataAccessTools aTools;
373cdf0e10cSrcweir         m_aConnection.reset(
374cdf0e10cSrcweir             aTools.connectRowset( Reference< XRowSet >( xForm, UNO_QUERY ), ::comphelper::getProcessServiceFactory(), sal_True ),
375cdf0e10cSrcweir             SharedConnection::NoTakeOwnership
376cdf0e10cSrcweir         );
377cdf0e10cSrcweir         // TODO: When incompatible changes (such as extending the "virtualdbtools" interface by ensureRowSetConnection)
378cdf0e10cSrcweir         // are allowed, again, we should change this: dbtools should consistently use SharedConnection all over
379cdf0e10cSrcweir         // the place, and connectRowset should be replaced with ensureRowSetConnection
380cdf0e10cSrcweir 
381cdf0e10cSrcweir         // get the fields of the object
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 	    if ( m_aConnection.is() && m_aObjectName.getLength() )
384cdf0e10cSrcweir         {
385cdf0e10cSrcweir             Reference< XComponent > xKeepFieldsAlive;
386cdf0e10cSrcweir             Reference< XNameAccess > xColumns = getFieldsByCommandDescriptor( m_aConnection, m_nObjectType, m_aObjectName,xKeepFieldsAlive );
387cdf0e10cSrcweir             if ( xColumns.is() )
388cdf0e10cSrcweir                 lcl_addToList(*pListBox,xColumns);
389cdf0e10cSrcweir         }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	    // Prefix setzen
392cdf0e10cSrcweir 	    UniString  aPrefix;
393cdf0e10cSrcweir         StringListResource aPrefixes( SVX_RES( RID_RSC_TABWIN_PREFIX ) );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	    switch (m_nObjectType)
396cdf0e10cSrcweir 	    {
397cdf0e10cSrcweir 		    case CommandType::TABLE:
398cdf0e10cSrcweir 			    aPrefix = aPrefixes[0];
399cdf0e10cSrcweir 			    break;
400cdf0e10cSrcweir 		    case CommandType::QUERY:
401cdf0e10cSrcweir 			    aPrefix = aPrefixes[1];
402cdf0e10cSrcweir 			    break;
403cdf0e10cSrcweir 		    default:
404cdf0e10cSrcweir 			    aPrefix = aPrefixes[2];
405cdf0e10cSrcweir 			    break;
406cdf0e10cSrcweir 	    }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 	    // an dem PropertySet nach Aenderungen der ControlSource lauschen
409cdf0e10cSrcweir 	    if (m_pChangeListener)
410cdf0e10cSrcweir 	    {
411cdf0e10cSrcweir 		    m_pChangeListener->dispose();
412cdf0e10cSrcweir 		    m_pChangeListener->release();
413cdf0e10cSrcweir 	    }
414cdf0e10cSrcweir 	    m_pChangeListener = new ::comphelper::OPropertyChangeMultiplexer(this, xSet);
415cdf0e10cSrcweir 	    m_pChangeListener->acquire();
416cdf0e10cSrcweir 	    m_pChangeListener->addProperty(FM_PROP_DATASOURCE);
417cdf0e10cSrcweir 	    m_pChangeListener->addProperty(FM_PROP_COMMAND);
418cdf0e10cSrcweir 	    m_pChangeListener->addProperty(FM_PROP_COMMANDTYPE);
419cdf0e10cSrcweir 
420cdf0e10cSrcweir         // Titel setzen
421cdf0e10cSrcweir 	    aTitle.AppendAscii(" ");
422cdf0e10cSrcweir 	    aTitle += aPrefix;
423cdf0e10cSrcweir 	    aTitle.AppendAscii(" ");
424cdf0e10cSrcweir 	    aTitle += m_aObjectName.getStr();
425cdf0e10cSrcweir 	    SetText( aTitle );
426cdf0e10cSrcweir     }
427cdf0e10cSrcweir     catch( const Exception& )
428cdf0e10cSrcweir     {
429cdf0e10cSrcweir         DBG_ERROR( "FmTabWin::UpdateContent: caught an exception!" );
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir //-----------------------------------------------------------------------
Resize()434cdf0e10cSrcweir void FmFieldWin::Resize()
435cdf0e10cSrcweir {
436cdf0e10cSrcweir 	SfxFloatingWindow::Resize();
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	Point aPos(GetPosPixel());
439cdf0e10cSrcweir 	Size aOutputSize( GetOutputSizePixel() );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	// Groesse der ::com::sun::star::form::ListBox anpassen
444cdf0e10cSrcweir 	Point aLBPos( LISTBOX_BORDER, LISTBOX_BORDER );
445cdf0e10cSrcweir 	Size aLBSize( aOutputSize );
446cdf0e10cSrcweir 	aLBSize.Width() -= (2*LISTBOX_BORDER);
447cdf0e10cSrcweir 	aLBSize.Height() -= (2*LISTBOX_BORDER);
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	pListBox->SetPosSizePixel( aLBPos, aLBSize );
450cdf0e10cSrcweir }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir //-----------------------------------------------------------------------
FillInfo(SfxChildWinInfo & rInfo) const453cdf0e10cSrcweir void FmFieldWin::FillInfo( SfxChildWinInfo& rInfo ) const
454cdf0e10cSrcweir {
455cdf0e10cSrcweir 	rInfo.bVisible = sal_False;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir //-----------------------------------------------------------------------
SFX_IMPL_FLOATINGWINDOW(FmFieldWinMgr,SID_FM_ADD_FIELD)459cdf0e10cSrcweir SFX_IMPL_FLOATINGWINDOW(FmFieldWinMgr, SID_FM_ADD_FIELD)
460cdf0e10cSrcweir 
461cdf0e10cSrcweir //-----------------------------------------------------------------------
462cdf0e10cSrcweir FmFieldWinMgr::FmFieldWinMgr(Window* _pParent, sal_uInt16 _nId,
463cdf0e10cSrcweir 			   SfxBindings* _pBindings, SfxChildWinInfo* _pInfo)
464cdf0e10cSrcweir 			  :SfxChildWindow(_pParent, _nId)
465cdf0e10cSrcweir {
466cdf0e10cSrcweir 	pWindow = new FmFieldWin(_pBindings, this, _pParent);
467cdf0e10cSrcweir 	SetHideNotDelete(sal_True);
468cdf0e10cSrcweir 	eChildAlignment = SFX_ALIGN_NOALIGNMENT;
469cdf0e10cSrcweir 	((SfxFloatingWindow*)pWindow)->Initialize( _pInfo );
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 
473