merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / control / RelationControl.cxx
blob4fb4dfb471b498b1047ab66f9e0eb0e479397674
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RelationControl.cxx,v $
10 * $Revision: 1.23.6.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_RELATIONCONTROL_HXX
34 #include "RelationControl.hxx"
35 #endif
36 #ifndef DBACCESS_SOURCE_UI_INC_RELATIONCONTROL_HRC
37 #include "RelationControl.hrc"
38 #endif
40 #ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
41 #include <svtools/editbrowsebox.hxx>
42 #endif
43 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #endif
46 #ifndef _TOOLS_DEBUG_HXX
47 #include <tools/debug.hxx>
48 #endif
49 #ifndef TOOLS_DIAGNOSE_EX_H
50 #include <tools/diagnose_ex.h>
51 #endif
52 #ifndef DBAUI_TABLECONNECTIONDATA_HXX
53 #include "TableConnectionData.hxx"
54 #endif
55 #ifndef DBAUI_TABLECONNECTION_HXX
56 #include "TableConnection.hxx"
57 #endif
58 #ifndef DBAUI_TABLEWINDOW_HXX
59 #include "TableWindow.hxx"
60 #endif
61 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
62 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
63 #endif
64 #ifndef DBAUI_TOOLS_HXX
65 #include "UITools.hxx"
66 #endif
67 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
68 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
69 #endif
70 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
71 #include <com/sun/star/container/XNameAccess.hpp>
72 #endif
73 #ifndef DBAUI_RELCONTROLIFACE_HXX
74 #include "RelControliFace.hxx"
75 #endif
76 #ifndef _DBU_CONTROL_HRC_
77 #include "dbu_control.hrc"
78 #endif
79 #ifndef _DBA_DBACCESS_HELPID_HRC_
80 #include "dbaccess_helpid.hrc"
81 #endif
82 #ifndef _TOOLS_DEBUG_HXX
83 #include <tools/debug.hxx>
84 #endif
86 #include <algorithm>
88 #define SOURCE_COLUMN 1
89 #define DEST_COLUMN 2
91 namespace dbaui
93 using namespace ::com::sun::star::uno;
94 using namespace ::com::sun::star::beans;
95 using namespace ::com::sun::star::sdbc;
96 using namespace ::com::sun::star::sdbcx;
97 using namespace ::com::sun::star::container;
98 using namespace svt;
100 typedef ::svt::EditBrowseBox ORelationControl_Base;
101 class ORelationControl : public ORelationControl_Base
103 friend class OTableListBoxControl;
105 ::std::auto_ptr< ::svt::ListBoxControl> m_pListCell;
106 TTableConnectionData::value_type m_pConnData;
107 const OJoinTableView::OTableWindowMap* m_pTableMap;
108 OTableListBoxControl* m_pBoxControl;
109 long m_nDataPos;
110 Reference< XPropertySet> m_xSourceDef;
111 Reference< XPropertySet> m_xDestDef;
114 void fillListBox(const Reference< XPropertySet>& _xDest,long nRow,USHORT nColumnId);
115 /** returns the column id for the editbrowsebox
116 @param _nColId
117 the column id SOURCE_COLUMN or DEST_COLUMN
119 @return the current column id eihter SOURCE_COLUMN or DEST_COLUMN depends on the connection data
121 USHORT getColumnIdent( USHORT _nColId ) const;
122 public:
123 ORelationControl( OTableListBoxControl* pParent,const OJoinTableView::OTableWindowMap* _pTableMap );
124 virtual ~ORelationControl();
126 /** searches for a connection between these two tables
127 @param _pSource
128 the left table
129 @param _pDest
130 the right window
132 void setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest);
134 /** allows to access the connection data from outside
136 @return rthe connection data
138 inline TTableConnectionData::value_type getData() const { return m_pConnData; }
140 void lateInit();
142 protected:
143 virtual void Resize();
145 virtual long PreNotify(NotifyEvent& rNEvt );
147 virtual BOOL IsTabAllowed(BOOL bForward) const;
149 virtual void Init(const TTableConnectionData::value_type& _pConnData);
150 virtual void Init() { ORelationControl_Base::Init(); }
151 virtual void InitController( ::svt::CellControllerRef& rController, long nRow, USHORT nCol );
152 virtual ::svt::CellController* GetController( long nRow, USHORT nCol );
153 virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColId ) const;
154 virtual BOOL SeekRow( long nRow );
155 virtual BOOL SaveModified();
156 virtual String GetCellText( long nRow, USHORT nColId ) const;
158 virtual void CellModified();
160 DECL_LINK( AsynchDeactivate, void* );
161 private:
163 DECL_LINK( AsynchActivate, void* );
167 //========================================================================
168 // class ORelationControl
169 //========================================================================
170 DBG_NAME(ORelationControl)
171 //------------------------------------------------------------------------
172 ORelationControl::ORelationControl( OTableListBoxControl* pParent ,const OJoinTableView::OTableWindowMap* _pTableMap)
173 :EditBrowseBox( pParent, EBBF_SMART_TAB_TRAVEL | EBBF_NOROWPICTURE, WB_TABSTOP | /*WB_3DLOOK | */WB_BORDER | BROWSER_AUTOSIZE_LASTCOL)
174 ,m_pTableMap(_pTableMap)
175 ,m_pBoxControl(pParent)
176 ,m_xSourceDef( NULL )
177 ,m_xDestDef( NULL )
179 DBG_CTOR(ORelationControl,NULL);
182 //------------------------------------------------------------------------
183 ORelationControl::~ORelationControl()
185 DBG_DTOR(ORelationControl,NULL);
188 //------------------------------------------------------------------------
189 void ORelationControl::Init(const TTableConnectionData::value_type& _pConnData)
191 DBG_CHKTHIS(ORelationControl,NULL);
193 m_pConnData = _pConnData;
194 OSL_ENSURE(m_pConnData, "No data supplied!");
196 m_pConnData->normalizeLines();
198 //------------------------------------------------------------------------------
199 void ORelationControl::lateInit()
201 if ( !m_pConnData.get() )
202 return;
203 m_xSourceDef = m_pConnData->getReferencingTable()->getTable();
204 m_xDestDef = m_pConnData->getReferencedTable()->getTable();
206 if ( ColCount() == 0 )
208 InsertDataColumn( SOURCE_COLUMN, m_pConnData->getReferencingTable()->GetWinName(), 100);
209 InsertDataColumn( DEST_COLUMN, m_pConnData->getReferencedTable()->GetWinName(), 100);
210 // wenn es die Defs noch nicht gibt, dann muessen sie noch mit SetSource-/-DestDef gesetzt werden !
212 m_pListCell.reset( new ListBoxControl( &GetDataWindow() ) );
214 //////////////////////////////////////////////////////////////////////
215 // set browse mode
216 SetMode( BROWSER_COLUMNSELECTION |
217 BROWSER_HLINESFULL |
218 BROWSER_VLINESFULL |
219 BROWSER_HIDECURSOR |
220 BROWSER_HIDESELECT |
221 BROWSER_AUTO_HSCROLL |
222 BROWSER_AUTO_VSCROLL);
224 else
225 // not the first call
226 RowRemoved(0, GetRowCount());
228 RowInserted(0, m_pConnData->GetConnLineDataList()->size() + 1, TRUE); // add one extra row
230 //------------------------------------------------------------------------------
231 void ORelationControl::Resize()
233 DBG_CHKTHIS(ORelationControl,NULL);
234 EditBrowseBox::Resize();
235 long nOutputWidth = GetOutputSizePixel().Width();
236 SetColumnWidth(1, (nOutputWidth / 2));
237 SetColumnWidth(2, (nOutputWidth / 2));
240 //------------------------------------------------------------------------------
241 long ORelationControl::PreNotify(NotifyEvent& rNEvt)
243 DBG_CHKTHIS(ORelationControl,NULL);
244 if (rNEvt.GetType() == EVENT_LOSEFOCUS && !HasChildPathFocus() )
245 PostUserEvent(LINK(this, ORelationControl, AsynchDeactivate));
246 else if (rNEvt.GetType() == EVENT_GETFOCUS)
247 PostUserEvent(LINK(this, ORelationControl, AsynchActivate));
249 return EditBrowseBox::PreNotify(rNEvt);
252 //------------------------------------------------------------------------------
253 IMPL_LINK(ORelationControl, AsynchActivate, void*, EMPTYARG)
255 ActivateCell();
256 return 0L;
259 //------------------------------------------------------------------------------
260 IMPL_LINK(ORelationControl, AsynchDeactivate, void*, EMPTYARG)
262 DeactivateCell();
263 return 0L;
266 //------------------------------------------------------------------------------
267 BOOL ORelationControl::IsTabAllowed(BOOL bForward) const
269 DBG_CHKTHIS(ORelationControl,NULL);
270 long nRow = GetCurRow();
271 USHORT nCol = GetCurColumnId();
273 BOOL bRet = !(( ( bForward && (nCol == DEST_COLUMN) && (nRow == GetRowCount() - 1)))
274 || (!bForward && (nCol == SOURCE_COLUMN) && (nRow == 0)));
276 return bRet && EditBrowseBox::IsTabAllowed(bForward);
279 //------------------------------------------------------------------------------
280 BOOL ORelationControl::SaveModified()
282 DBG_CHKTHIS(ORelationControl,NULL);
283 sal_Int32 nRow = GetCurRow();
284 if ( nRow != BROWSER_ENDOFSELECTION )
286 String sFieldName(m_pListCell->GetSelectEntry());
287 OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
288 if ( pLines->size() <= static_cast<sal_uInt32>(nRow) )
290 pLines->push_back(new OConnectionLineData());
291 nRow = pLines->size() - 1;
294 OConnectionLineDataRef pConnLineData = (*pLines)[nRow];
296 switch( getColumnIdent( GetCurColumnId() ) )
298 case SOURCE_COLUMN:
299 pConnLineData->SetSourceFieldName( sFieldName );
300 break;
301 case DEST_COLUMN:
302 pConnLineData->SetDestFieldName( sFieldName );
303 break;
307 return TRUE;
309 //------------------------------------------------------------------------------
310 USHORT ORelationControl::getColumnIdent( USHORT _nColId ) const
312 USHORT nId = _nColId;
313 if ( m_pConnData->getReferencingTable() != m_pBoxControl->getReferencingTable() )
314 nId = ( _nColId == SOURCE_COLUMN) ? DEST_COLUMN : SOURCE_COLUMN;
315 return nId;
318 //------------------------------------------------------------------------------
319 String ORelationControl::GetCellText( long nRow, USHORT nColId ) const
321 DBG_CHKTHIS(ORelationControl,NULL);
322 String sText;
323 if ( m_pConnData->GetConnLineDataList()->size() > static_cast<size_t>(nRow) )
325 OConnectionLineDataRef pConnLineData = (*m_pConnData->GetConnLineDataList())[nRow];
326 switch( getColumnIdent( nColId ) )
328 case SOURCE_COLUMN:
329 sText = pConnLineData->GetSourceFieldName();
330 break;
331 case DEST_COLUMN:
332 sText = pConnLineData->GetDestFieldName();
333 break;
336 return sText;
339 //------------------------------------------------------------------------------
340 void ORelationControl::InitController( CellControllerRef& /*rController*/, long nRow, USHORT nColumnId )
342 DBG_CHKTHIS(ORelationControl,NULL);
344 ULONG nHelpId = HID_RELATIONDIALOG_LEFTFIELDCELL;
346 Reference< XPropertySet> xDef;
347 switch ( getColumnIdent(nColumnId) )
349 case SOURCE_COLUMN:
350 xDef = m_xSourceDef;
351 nHelpId = HID_RELATIONDIALOG_LEFTFIELDCELL;
352 break;
353 case DEST_COLUMN:
354 xDef = m_xDestDef;
355 nHelpId = HID_RELATIONDIALOG_RIGHTFIELDCELL;
356 break;
357 default:
358 // ?????????
359 break;
362 if ( xDef.is() )
364 fillListBox(xDef,nRow,nColumnId);
365 String sName = GetCellText( nRow, nColumnId );
366 m_pListCell->SelectEntry( sName );
367 if ( m_pListCell->GetSelectEntry() != sName )
369 m_pListCell->InsertEntry( sName );
370 m_pListCell->SelectEntry( sName );
373 m_pListCell->SetHelpId(nHelpId);
377 //------------------------------------------------------------------------------
378 CellController* ORelationControl::GetController( long /*nRow*/, USHORT /*nColumnId*/ )
380 DBG_CHKTHIS(ORelationControl,NULL);
381 return new ListBoxCellController( m_pListCell.get() );
384 //------------------------------------------------------------------------------
385 BOOL ORelationControl::SeekRow( long nRow )
387 DBG_CHKTHIS(ORelationControl,NULL);
388 m_nDataPos = nRow;
389 return TRUE;
392 //------------------------------------------------------------------------------
393 void ORelationControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColumnId ) const
395 DBG_CHKTHIS(ORelationControl,NULL);
396 String aText =const_cast< ORelationControl*>(this)->GetCellText( m_nDataPos, nColumnId );
398 Point aPos( rRect.TopLeft() );
399 Size aTextSize( GetDataWindow().GetTextHeight(),GetDataWindow().GetTextWidth( aText ));
401 if( aPos.X() < rRect.Right() || aPos.X() + aTextSize.Width() > rRect.Right() ||
402 aPos.Y() < rRect.Top() || aPos.Y() + aTextSize.Height() > rRect.Bottom() )
403 rDev.SetClipRegion( rRect );
405 rDev.DrawText( aPos, aText );
407 if( rDev.IsClipRegion() )
408 rDev.SetClipRegion();
410 // -----------------------------------------------------------------------------
411 void ORelationControl::fillListBox(const Reference< XPropertySet>& _xDest,long /*_nRow*/,USHORT /*nColumnId*/)
413 m_pListCell->Clear();
416 if ( _xDest.is() )
418 //sal_Int32 nRows = GetRowCount();
419 Reference<XColumnsSupplier> xSup(_xDest,UNO_QUERY);
420 Reference<XNameAccess> xColumns = xSup->getColumns();
421 Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
422 const ::rtl::OUString* pIter = aNames.getConstArray();
423 const ::rtl::OUString* pEnd = pIter + aNames.getLength();
424 for(;pIter != pEnd;++pIter)
426 m_pListCell->InsertEntry( *pIter );
428 m_pListCell->InsertEntry(String(), 0);
431 catch( const Exception& )
433 DBG_UNHANDLED_EXCEPTION();
436 // -----------------------------------------------------------------------------
437 void ORelationControl::setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest)
439 // wenn ich hier gerade editiere, ausblenden
440 BOOL bWasEditing = IsEditing();
441 if ( bWasEditing )
442 DeactivateCell();
444 if ( _pSource && _pDest )
446 m_xSourceDef = _pSource->GetTable();
447 SetColumnTitle(1, _pSource->GetName());
450 m_xDestDef = _pDest->GetTable();
451 SetColumnTitle(2, _pDest->GetName());
453 const OJoinTableView* pView = _pSource->getTableView();
454 OTableConnection* pConn = pView->GetTabConn(_pSource,_pDest);
455 if ( pConn && !m_pConnData->GetConnLineDataList()->empty() )
457 m_pConnData->CopyFrom(*pConn->GetData());
458 m_pBoxControl->getContainer()->notifyConnectionChange();
460 else
462 // no connection found so we clear our data
463 OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
464 ::std::for_each(pLines->begin(),
465 pLines->end(),
466 OUnaryRefFunctor<OConnectionLineData>( ::std::mem_fun(&OConnectionLineData::Reset))
469 m_pConnData->setReferencingTable(_pSource->GetData());
470 m_pConnData->setReferencedTable(_pDest->GetData());
472 m_pConnData->normalizeLines();
475 // neu zeichnen
476 Invalidate();
478 if ( bWasEditing )
480 GoToRow(0);
481 ActivateCell();
484 //------------------------------------------------------------------------
485 void ORelationControl::CellModified()
487 DBG_CHKTHIS(ORelationControl,NULL);
488 EditBrowseBox::CellModified();
489 SaveModified();
490 static_cast<OTableListBoxControl*>(GetParent())->NotifyCellChange();
492 //========================================================================
493 // class OTableListBoxControl
494 DBG_NAME(OTableListBoxControl)
496 //========================================================================
498 OTableListBoxControl::OTableListBoxControl( Window* _pParent
499 ,const ResId& _rResId
500 ,const OJoinTableView::OTableWindowMap* _pTableMap
501 ,IRelationControlInterface* _pParentDialog)
502 : Window(_pParent,_rResId)
503 , m_aFL_InvolvedTables( this, ResId(FL_INVOLVED_TABLES,*_rResId.GetResMgr()))
504 , m_lmbLeftTable( this, ResId(LB_LEFT_TABLE,*_rResId.GetResMgr()))
505 , m_lmbRightTable( this, ResId(LB_RIGHT_TABLE,*_rResId.GetResMgr()))
506 , m_aFL_InvolvedFields( this, ResId(FL_INVOLVED_FIELDS,*_rResId.GetResMgr()))
507 , m_pTableMap(_pTableMap)
508 , m_pParentDialog(_pParentDialog)
510 m_pRC_Tables = new ORelationControl( this,m_pTableMap );
511 m_pRC_Tables->SetHelpId(HID_RELDLG_KEYFIELDS);
512 m_pRC_Tables->Init( );
513 m_pRC_Tables->SetZOrder(&m_lmbRightTable, WINDOW_ZORDER_BEHIND);
515 lateUIInit();
517 Link aLink(LINK(this, OTableListBoxControl, OnTableChanged));
518 m_lmbLeftTable.SetSelectHdl(aLink);
519 m_lmbRightTable.SetSelectHdl(aLink);
521 FreeResource();
522 DBG_CTOR(OTableListBoxControl,NULL);
524 // -----------------------------------------------------------------------------
525 OTableListBoxControl::~OTableListBoxControl()
527 ORelationControl* pTemp = m_pRC_Tables;
528 m_pRC_Tables = NULL;
529 delete pTemp;
530 DBG_DTOR(OTableListBoxControl,NULL);
532 // -----------------------------------------------------------------------------
533 void OTableListBoxControl::fillListBoxes()
535 DBG_ASSERT( !m_pTableMap->empty(), "OTableListBoxControl::fillListBoxes: no table window!");
536 OTableWindow* pInitialLeft = NULL;
537 OTableWindow* pInitialRight = NULL;
539 // die Namen aller TabWins einsammeln
540 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
541 OJoinTableView::OTableWindowMap::const_iterator aEnd = m_pTableMap->end();
542 for(;aIter != aEnd;++aIter)
544 m_lmbLeftTable.InsertEntry(aIter->first);
545 m_lmbRightTable.InsertEntry(aIter->first);
547 if (!pInitialLeft)
549 pInitialLeft = aIter->second;
550 m_strCurrentLeft = aIter->first;
552 else if (!pInitialRight)
554 pInitialRight = aIter->second;
555 m_strCurrentRight = aIter->first;
557 } // for(;aIter != m_pTableMap->end();++aIter)
559 if ( !pInitialRight )
561 pInitialRight = pInitialLeft;
562 m_strCurrentRight = m_strCurrentLeft;
565 // die entsprechenden Defs an mein Controls
566 m_pRC_Tables->setWindowTables(pInitialLeft,pInitialRight);
568 // die in einer ComboBox ausgewaehlte Tabelle darf nicht in der anderen zur Verfuegung stehen
570 if ( m_pTableMap->size() > 2 )
572 m_lmbLeftTable.RemoveEntry(m_strCurrentRight);
573 m_lmbRightTable.RemoveEntry(m_strCurrentLeft);
576 // links das erste, rechts das zweite selektieren
577 m_lmbLeftTable.SelectEntry(m_strCurrentLeft);
578 m_lmbRightTable.SelectEntry(m_strCurrentRight);
580 m_lmbLeftTable.GrabFocus();
582 // -----------------------------------------------------------------------------
583 IMPL_LINK( OTableListBoxControl, OnTableChanged, ListBox*, pListBox )
585 String strSelected(pListBox->GetSelectEntry());
586 OTableWindow* pLeft = NULL;
587 OTableWindow* pRight = NULL;
589 // eine Sonderbehandlung : wenn es nur zwei Tabellen gibt, muss ich bei Wechsel in einer LB auch in der anderen umschalten
590 if ( m_pTableMap->size() == 2 )
592 ListBox* pOther;
593 if ( pListBox == &m_lmbLeftTable )
594 pOther = &m_lmbRightTable;
595 else
596 pOther = &m_lmbLeftTable;
597 pOther->SelectEntryPos(1 - pOther->GetSelectEntryPos());
599 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
600 OTableWindow* pFirst = aIter->second;
601 ++aIter;
602 OTableWindow* pSecond = aIter->second;
604 if ( m_lmbLeftTable.GetSelectEntry() == String(pFirst->GetName()) )
606 pLeft = pFirst;
607 pRight = pSecond;
609 else
611 pLeft = pSecond;
612 pRight = pFirst;
615 else
617 // zuerst brauche ich die TableDef zur Tabelle, dazu das TabWin
618 OJoinTableView::OTableWindowMap::const_iterator aFind = m_pTableMap->find(strSelected);
619 OTableWindow* pLoop = NULL;
620 if( aFind != m_pTableMap->end() )
621 pLoop = aFind->second;
622 DBG_ASSERT(pLoop != NULL, "ORelationDialog::OnTableChanged : ungueltiger Eintrag in ListBox !");
623 // da ich die ListBoxen selber mit eben diesen Tabellennamen, mit denen ich sie jetzt vergleiche, gefuellt habe,
624 // MUSS ich strSelected finden
625 if (pListBox == &m_lmbLeftTable)
627 // den vorher links selektierten Eintrag wieder rein rechts
628 m_lmbRightTable.InsertEntry(m_strCurrentLeft);
629 // und den jetzt selektierten raus
630 m_lmbRightTable.RemoveEntry(strSelected);
631 m_strCurrentLeft = strSelected;
633 pLeft = pLoop;
635 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_lmbRightTable.GetSelectEntry());
636 OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
637 if ( aIter != m_pTableMap->end() )
638 pRight = aIter->second;
640 m_lmbLeftTable.GrabFocus();
642 else
644 // den vorher rechts selektierten Eintrag wieder rein links
645 m_lmbLeftTable.InsertEntry(m_strCurrentRight);
646 // und den jetzt selektierten raus
647 m_lmbLeftTable.RemoveEntry(strSelected);
648 m_strCurrentRight = strSelected;
650 pRight = pLoop;
651 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_lmbLeftTable.GetSelectEntry());
652 OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
653 if ( aIter != m_pTableMap->end() )
654 pLeft = aIter->second;
658 pListBox->GrabFocus();
660 m_pRC_Tables->setWindowTables(pLeft,pRight);
662 NotifyCellChange();
663 return 0;
665 // -----------------------------------------------------------------------------
666 void OTableListBoxControl::NotifyCellChange()
668 // den Ok-Button en- oder disablen, je nachdem, ob ich eine gueltige Situation habe
669 TTableConnectionData::value_type pConnData = m_pRC_Tables->getData();
670 const OConnectionLineDataVec* pLines = pConnData->GetConnLineDataList();
671 m_pParentDialog->setValid(!pLines->empty());
673 if ( pLines->size() >= static_cast<sal_uInt32>(m_pRC_Tables->GetRowCount()) )
675 m_pRC_Tables->DeactivateCell();
676 m_pRC_Tables->RowInserted(m_pRC_Tables->GetRowCount(), pLines->size() - static_cast<sal_uInt32>(m_pRC_Tables->GetRowCount()) + 1, TRUE);
677 m_pRC_Tables->ActivateCell();
680 // -----------------------------------------------------------------------------
681 void fillEntryAndDisable(ListBox& _rListBox,const String& _sEntry)
683 _rListBox.InsertEntry(_sEntry);
684 _rListBox.SelectEntryPos(0);
685 _rListBox.Disable();
687 // -----------------------------------------------------------------------------
688 void OTableListBoxControl::fillAndDisable(const TTableConnectionData::value_type& _pConnectionData)
690 fillEntryAndDisable(m_lmbLeftTable,_pConnectionData->getReferencingTable()->GetWinName());
691 fillEntryAndDisable(m_lmbRightTable,_pConnectionData->getReferencedTable()->GetWinName());
693 // -----------------------------------------------------------------------------
694 void OTableListBoxControl::Init(const TTableConnectionData::value_type& _pConnData)
696 m_pRC_Tables->Init(_pConnData);
698 // -----------------------------------------------------------------------------
699 void OTableListBoxControl::lateUIInit(Window* _pTableSeparator)
701 const sal_Int32 nDiff = LogicToPixel( Point(0,6), MAP_APPFONT ).Y();
702 Point aDlgPoint = LogicToPixel( Point(12,43), MAP_APPFONT );
703 if ( _pTableSeparator )
705 _pTableSeparator->SetZOrder(&m_lmbRightTable, WINDOW_ZORDER_BEHIND);
706 m_pRC_Tables->SetZOrder(_pTableSeparator, WINDOW_ZORDER_BEHIND);
707 //aDlgPoint = m_pTableSeparator->GetPosPixel() + Point(0,aSize.Height()) + LogicToPixel( Point(0,6), MAP_APPFONT );
708 _pTableSeparator->SetPosPixel(Point(0,m_aFL_InvolvedFields.GetPosPixel().Y()));
709 const Size aSize = _pTableSeparator->GetSizePixel();
710 aDlgPoint.Y() = _pTableSeparator->GetPosPixel().Y() + aSize.Height();
711 m_aFL_InvolvedFields.SetPosPixel(Point(m_aFL_InvolvedFields.GetPosPixel().X(),aDlgPoint.Y()));
712 aDlgPoint.Y() += nDiff + m_aFL_InvolvedFields.GetSizePixel().Height();
714 //////////////////////////////////////////////////////////////////////
715 // positing BrowseBox control
716 const Size aCurrentSize = GetSizePixel();
717 Size aDlgSize = LogicToPixel( Size(24,0), MAP_APPFONT );
718 aDlgSize.Width() = aCurrentSize.Width() - aDlgSize.Width();
719 aDlgSize.Height() = aCurrentSize.Height() - aDlgPoint.Y() - nDiff;
721 m_pRC_Tables->SetPosSizePixel( aDlgPoint, aDlgSize );
722 m_pRC_Tables->Show();
724 lateInit();
726 // -----------------------------------------------------------------------------
727 void OTableListBoxControl::lateInit()
729 m_pRC_Tables->lateInit();
731 // -----------------------------------------------------------------------------
732 BOOL OTableListBoxControl::SaveModified()
734 BOOL bRet = m_pRC_Tables->SaveModified();
735 m_pRC_Tables->getData()->normalizeLines();
736 return bRet;
738 // -----------------------------------------------------------------------------
739 TTableWindowData::value_type OTableListBoxControl::getReferencingTable() const
741 return m_pRC_Tables->getData()->getReferencingTable();
743 // -----------------------------------------------------------------------------
744 void OTableListBoxControl::enableRelation(bool _bEnable)
746 if ( !_bEnable )
747 PostUserEvent(LINK(m_pRC_Tables, ORelationControl, AsynchDeactivate));
748 m_pRC_Tables->Enable(_bEnable);
751 // -----------------------------------------------------------------------------
753 // -----------------------------------------------------------------------------