update credits
[LibreOffice.git] / dbaccess / source / ui / control / RelationControl.cxx
blobd61d39e9d986966df6b21d4064b672071af6a769
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "RelationControl.hxx"
21 #include "RelationControl.hrc"
23 #include <svtools/editbrowsebox.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <tools/diagnose_ex.h>
26 #include "TableConnectionData.hxx"
27 #include "TableConnection.hxx"
28 #include "TableWindow.hxx"
29 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
30 #include "UITools.hxx"
31 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
32 #include <com/sun/star/container/XNameAccess.hpp>
33 #include "RelControliFace.hxx"
34 #include "dbu_control.hrc"
35 #include "dbaccess_helpid.hrc"
36 #include <osl/diagnose.h>
38 #include <algorithm>
39 #include <list>
40 using std::list;
41 #include <utility>
42 using std::pair;
43 using std::make_pair;
45 #define SOURCE_COLUMN 1
46 #define DEST_COLUMN 2
48 namespace dbaui
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::beans;
52 using namespace ::com::sun::star::sdbc;
53 using namespace ::com::sun::star::sdbcx;
54 using namespace ::com::sun::star::container;
55 using namespace svt;
57 typedef ::svt::EditBrowseBox ORelationControl_Base;
58 class ORelationControl : public ORelationControl_Base
60 friend class OTableListBoxControl;
62 ::std::auto_ptr< ::svt::ListBoxControl> m_pListCell;
63 TTableConnectionData::value_type m_pConnData;
64 OTableListBoxControl* m_pBoxControl;
65 long m_nDataPos;
66 Reference< XPropertySet> m_xSourceDef;
67 Reference< XPropertySet> m_xDestDef;
68 enum opcode { DELETE, INSERT, MODIFY };
69 typedef list< pair < opcode, pair < OConnectionLineDataVec::size_type, OConnectionLineDataVec::size_type> > > ops_type;
70 ops_type m_ops;
73 void fillListBox(const Reference< XPropertySet>& _xDest,long nRow,sal_uInt16 nColumnId);
74 /** returns the column id for the editbrowsebox
75 @param _nColId
76 the column id SOURCE_COLUMN or DEST_COLUMN
78 @return the current column id eihter SOURCE_COLUMN or DEST_COLUMN depends on the connection data
80 sal_uInt16 getColumnIdent( sal_uInt16 _nColId ) const;
81 public:
82 ORelationControl( OTableListBoxControl* pParent );
83 virtual ~ORelationControl();
85 /** searches for a connection between these two tables
86 @param _pSource
87 the left table
88 @param _pDest
89 the right window
91 void setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest);
93 /** allows to access the connection data from outside
95 @return rthe connection data
97 inline TTableConnectionData::value_type getData() const { return m_pConnData; }
99 void lateInit();
101 protected:
102 virtual void Resize();
104 virtual long PreNotify(NotifyEvent& rNEvt );
106 virtual sal_Bool IsTabAllowed(sal_Bool bForward) const;
108 virtual void Init(const TTableConnectionData::value_type& _pConnData);
109 virtual void Init() { ORelationControl_Base::Init(); }
110 virtual void InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol );
111 virtual ::svt::CellController* GetController( long nRow, sal_uInt16 nCol );
112 virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId ) const;
113 virtual sal_Bool SeekRow( long nRow );
114 virtual sal_Bool SaveModified();
115 virtual String GetCellText( long nRow, sal_uInt16 nColId ) const;
117 virtual void CellModified();
119 DECL_LINK( AsynchDeactivate, void* );
120 private:
122 DECL_LINK( AsynchActivate, void* );
126 //========================================================================
127 // class ORelationControl
128 //========================================================================
129 DBG_NAME(ORelationControl)
130 //------------------------------------------------------------------------
131 ORelationControl::ORelationControl( OTableListBoxControl* pParent )
132 :EditBrowseBox( pParent, EBBF_SMART_TAB_TRAVEL | EBBF_NOROWPICTURE, WB_TABSTOP | WB_BORDER | BROWSER_AUTOSIZE_LASTCOL)
133 ,m_pBoxControl(pParent)
134 ,m_xSourceDef( NULL )
135 ,m_xDestDef( NULL )
137 DBG_CTOR(ORelationControl,NULL);
140 //------------------------------------------------------------------------
141 ORelationControl::~ORelationControl()
143 DBG_DTOR(ORelationControl,NULL);
146 //------------------------------------------------------------------------
147 void ORelationControl::Init(const TTableConnectionData::value_type& _pConnData)
149 DBG_CHKTHIS(ORelationControl,NULL);
151 m_pConnData = _pConnData;
152 OSL_ENSURE(m_pConnData, "No data supplied!");
154 m_pConnData->normalizeLines();
156 //------------------------------------------------------------------------------
157 void ORelationControl::lateInit()
159 if ( !m_pConnData.get() )
160 return;
161 m_xSourceDef = m_pConnData->getReferencingTable()->getTable();
162 m_xDestDef = m_pConnData->getReferencedTable()->getTable();
164 if ( ColCount() == 0 )
166 InsertDataColumn( SOURCE_COLUMN, m_pConnData->getReferencingTable()->GetWinName(), 100);
167 InsertDataColumn( DEST_COLUMN, m_pConnData->getReferencedTable()->GetWinName(), 100);
168 // If the Defs do not yet exits, we need to set them with SetSource-/-DestDef
170 m_pListCell.reset( new ListBoxControl( &GetDataWindow() ) );
172 //////////////////////////////////////////////////////////////////////
173 // set browse mode
174 SetMode( BROWSER_COLUMNSELECTION |
175 BROWSER_HLINESFULL |
176 BROWSER_VLINESFULL |
177 BROWSER_HIDECURSOR |
178 BROWSER_HIDESELECT |
179 BROWSER_AUTO_HSCROLL |
180 BROWSER_AUTO_VSCROLL);
182 else
183 // not the first call
184 RowRemoved(0, GetRowCount());
186 RowInserted(0, m_pConnData->GetConnLineDataList()->size() + 1, sal_True); // add one extra row
188 //------------------------------------------------------------------------------
189 void ORelationControl::Resize()
191 DBG_CHKTHIS(ORelationControl,NULL);
192 EditBrowseBox::Resize();
193 long nOutputWidth = GetOutputSizePixel().Width();
194 SetColumnWidth(1, (nOutputWidth / 2));
195 SetColumnWidth(2, (nOutputWidth / 2));
198 //------------------------------------------------------------------------------
199 long ORelationControl::PreNotify(NotifyEvent& rNEvt)
201 DBG_CHKTHIS(ORelationControl,NULL);
202 if (rNEvt.GetType() == EVENT_LOSEFOCUS && !HasChildPathFocus() )
203 PostUserEvent(LINK(this, ORelationControl, AsynchDeactivate));
204 else if (rNEvt.GetType() == EVENT_GETFOCUS)
205 PostUserEvent(LINK(this, ORelationControl, AsynchActivate));
207 return EditBrowseBox::PreNotify(rNEvt);
210 //------------------------------------------------------------------------------
211 IMPL_LINK_NOARG(ORelationControl, AsynchActivate)
213 ActivateCell();
214 return 0L;
217 //------------------------------------------------------------------------------
218 IMPL_LINK_NOARG(ORelationControl, AsynchDeactivate)
220 DeactivateCell();
221 return 0L;
224 //------------------------------------------------------------------------------
225 sal_Bool ORelationControl::IsTabAllowed(sal_Bool bForward) const
227 DBG_CHKTHIS(ORelationControl,NULL);
228 long nRow = GetCurRow();
229 sal_uInt16 nCol = GetCurColumnId();
231 sal_Bool bRet = !(( ( bForward && (nCol == DEST_COLUMN) && (nRow == GetRowCount() - 1)))
232 || (!bForward && (nCol == SOURCE_COLUMN) && (nRow == 0)));
234 return bRet && EditBrowseBox::IsTabAllowed(bForward);
237 //------------------------------------------------------------------------------
238 sal_Bool ORelationControl::SaveModified()
240 DBG_CHKTHIS(ORelationControl,NULL);
241 long nRow = GetCurRow();
242 if ( nRow != BROWSER_ENDOFSELECTION )
244 String sFieldName(m_pListCell->GetSelectEntry());
245 OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
246 if ( pLines->size() <= static_cast<OConnectionLineDataVec::size_type>(nRow) )
248 pLines->push_back(new OConnectionLineData());
249 nRow = pLines->size() - 1;
250 // add new past-pLines row
251 m_ops.push_back(make_pair(INSERT, make_pair(nRow+1, nRow+2)));
254 OConnectionLineDataRef pConnLineData = (*pLines)[nRow];
256 switch( getColumnIdent( GetCurColumnId() ) )
258 case SOURCE_COLUMN:
259 pConnLineData->SetSourceFieldName( sFieldName );
260 break;
261 case DEST_COLUMN:
262 pConnLineData->SetDestFieldName( sFieldName );
263 break;
265 // the modification we just did does *not* need to be registered in m_ops;
266 // it is already taken into account (by the codepath that called us)
267 //m_ops.push_back(make_pair(MODIFY, make_pair(nRow, nRow+1)));
270 const OConnectionLineDataVec::size_type oldSize = m_pConnData->GetConnLineDataList()->size();
271 OConnectionLineDataVec::size_type line = m_pConnData->normalizeLines();
272 const OConnectionLineDataVec::size_type newSize = m_pConnData->GetConnLineDataList()->size();
273 assert(newSize <= oldSize);
274 m_ops.push_back(make_pair(MODIFY, make_pair(line, newSize)));
275 m_ops.push_back(make_pair(DELETE, make_pair(newSize, oldSize)));
277 return sal_True;
279 //------------------------------------------------------------------------------
280 sal_uInt16 ORelationControl::getColumnIdent( sal_uInt16 _nColId ) const
282 sal_uInt16 nId = _nColId;
283 if ( m_pConnData->getReferencingTable() != m_pBoxControl->getReferencingTable() )
284 nId = ( _nColId == SOURCE_COLUMN) ? DEST_COLUMN : SOURCE_COLUMN;
285 return nId;
288 //------------------------------------------------------------------------------
289 String ORelationControl::GetCellText( long nRow, sal_uInt16 nColId ) const
291 DBG_CHKTHIS(ORelationControl,NULL);
292 String sText;
293 if ( m_pConnData->GetConnLineDataList()->size() > static_cast<size_t>(nRow) )
295 OConnectionLineDataRef pConnLineData = (*m_pConnData->GetConnLineDataList())[nRow];
296 switch( getColumnIdent( nColId ) )
298 case SOURCE_COLUMN:
299 sText = pConnLineData->GetSourceFieldName();
300 break;
301 case DEST_COLUMN:
302 sText = pConnLineData->GetDestFieldName();
303 break;
306 return sText;
309 //------------------------------------------------------------------------------
310 void ORelationControl::InitController( CellControllerRef& /*rController*/, long nRow, sal_uInt16 nColumnId )
312 DBG_CHKTHIS(ORelationControl,NULL);
314 OString sHelpId( HID_RELATIONDIALOG_LEFTFIELDCELL );
316 Reference< XPropertySet> xDef;
317 switch ( getColumnIdent(nColumnId) )
319 case SOURCE_COLUMN:
320 xDef = m_xSourceDef;
321 sHelpId = HID_RELATIONDIALOG_LEFTFIELDCELL;
322 break;
323 case DEST_COLUMN:
324 xDef = m_xDestDef;
325 sHelpId = HID_RELATIONDIALOG_RIGHTFIELDCELL;
326 break;
327 default:
328 // ?????????
329 break;
332 if ( xDef.is() )
334 fillListBox(xDef,nRow,nColumnId);
335 String sName = GetCellText( nRow, nColumnId );
336 m_pListCell->SelectEntry( sName );
337 if ( m_pListCell->GetSelectEntry() != sName )
339 m_pListCell->InsertEntry( sName );
340 m_pListCell->SelectEntry( sName );
343 m_pListCell->SetHelpId(sHelpId);
347 //------------------------------------------------------------------------------
348 CellController* ORelationControl::GetController( long /*nRow*/, sal_uInt16 /*nColumnId*/ )
350 DBG_CHKTHIS(ORelationControl,NULL);
351 return new ListBoxCellController( m_pListCell.get() );
354 //------------------------------------------------------------------------------
355 sal_Bool ORelationControl::SeekRow( long nRow )
357 DBG_CHKTHIS(ORelationControl,NULL);
358 m_nDataPos = nRow;
359 return sal_True;
362 //------------------------------------------------------------------------------
363 void ORelationControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
365 DBG_CHKTHIS(ORelationControl,NULL);
366 String aText =const_cast< ORelationControl*>(this)->GetCellText( m_nDataPos, nColumnId );
368 Point aPos( rRect.TopLeft() );
369 Size aTextSize( GetDataWindow().GetTextHeight(),GetDataWindow().GetTextWidth( aText ));
371 if( aPos.X() < rRect.Right() || aPos.X() + aTextSize.Width() > rRect.Right() ||
372 aPos.Y() < rRect.Top() || aPos.Y() + aTextSize.Height() > rRect.Bottom() )
374 rDev.SetClipRegion(Region(rRect));
377 rDev.DrawText( aPos, aText );
379 if( rDev.IsClipRegion() )
380 rDev.SetClipRegion();
382 // -----------------------------------------------------------------------------
383 void ORelationControl::fillListBox(const Reference< XPropertySet>& _xDest,long /*_nRow*/,sal_uInt16 /*nColumnId*/)
385 m_pListCell->Clear();
388 if ( _xDest.is() )
390 //sal_Int32 nRows = GetRowCount();
391 Reference<XColumnsSupplier> xSup(_xDest,UNO_QUERY);
392 Reference<XNameAccess> xColumns = xSup->getColumns();
393 Sequence< OUString> aNames = xColumns->getElementNames();
394 const OUString* pIter = aNames.getConstArray();
395 const OUString* pEnd = pIter + aNames.getLength();
396 for(;pIter != pEnd;++pIter)
398 m_pListCell->InsertEntry( *pIter );
400 m_pListCell->InsertEntry(String(), 0);
403 catch( const Exception& )
405 DBG_UNHANDLED_EXCEPTION();
408 // -----------------------------------------------------------------------------
409 void ORelationControl::setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest)
411 // If I edit here, hide
412 sal_Bool bWasEditing = IsEditing();
413 if ( bWasEditing )
414 DeactivateCell();
416 if ( _pSource && _pDest )
418 m_xSourceDef = _pSource->GetTable();
419 SetColumnTitle(1, _pSource->GetName());
422 m_xDestDef = _pDest->GetTable();
423 SetColumnTitle(2, _pDest->GetName());
425 const OJoinTableView* pView = _pSource->getTableView();
426 OTableConnection* pConn = pView->GetTabConn(_pSource,_pDest);
427 if ( pConn && !m_pConnData->GetConnLineDataList()->empty() )
429 m_pConnData->CopyFrom(*pConn->GetData());
430 m_pBoxControl->getContainer()->notifyConnectionChange();
432 else
434 // no connection found so we clear our data
435 OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
436 ::std::for_each(pLines->begin(),
437 pLines->end(),
438 OUnaryRefFunctor<OConnectionLineData>( ::std::mem_fun(&OConnectionLineData::Reset))
441 m_pConnData->setReferencingTable(_pSource->GetData());
442 m_pConnData->setReferencedTable(_pDest->GetData());
444 m_pConnData->normalizeLines();
447 // Repaint
448 Invalidate();
450 if ( bWasEditing )
452 GoToRow(0);
453 ActivateCell();
456 //------------------------------------------------------------------------
457 void ORelationControl::CellModified()
459 DBG_CHKTHIS(ORelationControl,NULL);
460 EditBrowseBox::CellModified();
461 SaveModified();
462 #if OSL_DEBUG_LEVEL > 0
463 OTableListBoxControl *parent = dynamic_cast<OTableListBoxControl*>(GetParent());
464 #else
465 OTableListBoxControl *parent = static_cast<OTableListBoxControl*>(GetParent());
466 #endif
467 assert(parent);
468 parent->NotifyCellChange();
470 //========================================================================
471 // class OTableListBoxControl
472 DBG_NAME(OTableListBoxControl)
474 //========================================================================
476 OTableListBoxControl::OTableListBoxControl( Window* _pParent
477 ,const ResId& _rResId
478 ,const OJoinTableView::OTableWindowMap* _pTableMap
479 ,IRelationControlInterface* _pParentDialog)
480 : Window(_pParent,_rResId)
481 , m_aFL_InvolvedTables( this, ResId(FL_INVOLVED_TABLES,*_rResId.GetResMgr()))
482 , m_lmbLeftTable( this, ResId(LB_LEFT_TABLE,*_rResId.GetResMgr()))
483 , m_lmbRightTable( this, ResId(LB_RIGHT_TABLE,*_rResId.GetResMgr()))
484 , m_aFL_InvolvedFields( this, ResId(FL_INVOLVED_FIELDS,*_rResId.GetResMgr()))
485 , m_pTableMap(_pTableMap)
486 , m_pParentDialog(_pParentDialog)
488 m_pRC_Tables = new ORelationControl( this );
489 m_pRC_Tables->SetHelpId(HID_RELDLG_KEYFIELDS);
490 m_pRC_Tables->Init( );
491 m_pRC_Tables->SetZOrder(&m_lmbRightTable, WINDOW_ZORDER_BEHIND);
493 lateUIInit();
495 Link aLink(LINK(this, OTableListBoxControl, OnTableChanged));
496 m_lmbLeftTable.SetSelectHdl(aLink);
497 m_lmbRightTable.SetSelectHdl(aLink);
499 FreeResource();
500 DBG_CTOR(OTableListBoxControl,NULL);
502 // -----------------------------------------------------------------------------
503 OTableListBoxControl::~OTableListBoxControl()
505 ORelationControl* pTemp = m_pRC_Tables;
506 m_pRC_Tables = NULL;
507 delete pTemp;
508 DBG_DTOR(OTableListBoxControl,NULL);
510 // -----------------------------------------------------------------------------
511 void OTableListBoxControl::fillListBoxes()
513 OSL_ENSURE( !m_pTableMap->empty(), "OTableListBoxControl::fillListBoxes: no table window!");
514 OTableWindow* pInitialLeft = NULL;
515 OTableWindow* pInitialRight = NULL;
517 // Collect the names of all TabWins
518 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
519 OJoinTableView::OTableWindowMap::const_iterator aEnd = m_pTableMap->end();
520 for(;aIter != aEnd;++aIter)
522 m_lmbLeftTable.InsertEntry(aIter->first);
523 m_lmbRightTable.InsertEntry(aIter->first);
525 if (!pInitialLeft)
527 pInitialLeft = aIter->second;
528 m_strCurrentLeft = aIter->first;
530 else if (!pInitialRight)
532 pInitialRight = aIter->second;
533 m_strCurrentRight = aIter->first;
537 if ( !pInitialRight )
539 pInitialRight = pInitialLeft;
540 m_strCurrentRight = m_strCurrentLeft;
543 // The corresponding Defs for my Controls
544 m_pRC_Tables->setWindowTables(pInitialLeft,pInitialRight);
546 // The table selected in a ComboBox must not be available in the other
548 if ( m_pTableMap->size() > 2 )
550 m_lmbLeftTable.RemoveEntry(m_strCurrentRight);
551 m_lmbRightTable.RemoveEntry(m_strCurrentLeft);
554 // Select the first one on the left side and on the right side,
555 // select the second one
556 m_lmbLeftTable.SelectEntry(m_strCurrentLeft);
557 m_lmbRightTable.SelectEntry(m_strCurrentRight);
559 m_lmbLeftTable.GrabFocus();
561 // -----------------------------------------------------------------------------
562 IMPL_LINK( OTableListBoxControl, OnTableChanged, ListBox*, pListBox )
564 String strSelected(pListBox->GetSelectEntry());
565 OTableWindow* pLeft = NULL;
566 OTableWindow* pRight = NULL;
568 // Special treatment: If there are only two tables, we need to switch the other one too when changing in a LB
569 if ( m_pTableMap->size() == 2 )
571 ListBox* pOther;
572 if ( pListBox == &m_lmbLeftTable )
573 pOther = &m_lmbRightTable;
574 else
575 pOther = &m_lmbLeftTable;
576 pOther->SelectEntryPos(1 - pOther->GetSelectEntryPos());
578 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
579 OTableWindow* pFirst = aIter->second;
580 ++aIter;
581 OTableWindow* pSecond = aIter->second;
583 if ( m_lmbLeftTable.GetSelectEntry() == String(pFirst->GetName()) )
585 pLeft = pFirst;
586 pRight = pSecond;
588 else
590 pLeft = pSecond;
591 pRight = pFirst;
594 else
596 // First we need the TableDef to the Table and with it the TabWin
597 OJoinTableView::OTableWindowMap::const_iterator aFind = m_pTableMap->find(strSelected);
598 OTableWindow* pLoop = NULL;
599 if( aFind != m_pTableMap->end() )
600 pLoop = aFind->second;
601 OSL_ENSURE(pLoop != NULL, "ORelationDialog::OnTableChanged: invalid ListBox entry!");
602 // We need to find strSelect, because we filled the ListBoxes with the table names with which we compare now
603 if (pListBox == &m_lmbLeftTable)
605 // Insert the previously selected Entry on the left side on the right side
606 m_lmbRightTable.InsertEntry(m_strCurrentLeft);
607 // Remove the currently selected Entry
608 m_lmbRightTable.RemoveEntry(strSelected);
609 m_strCurrentLeft = strSelected;
611 pLeft = pLoop;
613 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_lmbRightTable.GetSelectEntry());
614 OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
615 if ( aIter != m_pTableMap->end() )
616 pRight = aIter->second;
618 m_lmbLeftTable.GrabFocus();
620 else
622 // Insert the previously selected Entry on the right side on the left side
623 m_lmbLeftTable.InsertEntry(m_strCurrentRight);
624 // Remove the currently selected Entry
625 m_lmbLeftTable.RemoveEntry(strSelected);
626 m_strCurrentRight = strSelected;
628 pRight = pLoop;
629 OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_lmbLeftTable.GetSelectEntry());
630 OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
631 if ( aIter != m_pTableMap->end() )
632 pLeft = aIter->second;
636 pListBox->GrabFocus();
638 m_pRC_Tables->setWindowTables(pLeft,pRight);
640 NotifyCellChange();
641 return 0;
643 // -----------------------------------------------------------------------------
644 void OTableListBoxControl::NotifyCellChange()
646 // Enable/disable the OK button, depending on having a valid situation
647 TTableConnectionData::value_type pConnData = m_pRC_Tables->getData();
648 const OConnectionLineDataVec* pLines = pConnData->GetConnLineDataList();
649 bool bValid = !pLines->empty();
650 if (bValid)
652 OConnectionLineDataVec::const_iterator l(pLines->begin());
653 const OConnectionLineDataVec::const_iterator le(pLines->end());
654 for (; bValid && l!=le; ++l)
656 bValid = ! ((*l)->GetSourceFieldName().isEmpty() || (*l)->GetDestFieldName().isEmpty());
659 m_pParentDialog->setValid(bValid);
661 ORelationControl::ops_type::iterator i (m_pRC_Tables->m_ops.begin());
662 const ORelationControl::ops_type::const_iterator e (m_pRC_Tables->m_ops.end());
663 m_pRC_Tables->DeactivateCell();
664 for(; i != e; ++i)
666 switch(i->first)
668 case ORelationControl::DELETE:
669 m_pRC_Tables->RowRemoved(i->second.first, i->second.second - i->second.first);
670 break;
671 case ORelationControl::INSERT:
672 m_pRC_Tables->RowInserted(i->second.first, i->second.second - i->second.first);
673 break;
674 case ORelationControl::MODIFY:
675 for(OConnectionLineDataVec::size_type j = i->second.first; j < i->second.second; ++j)
676 m_pRC_Tables->RowModified(j);
677 break;
680 m_pRC_Tables->ActivateCell();
681 m_pRC_Tables->m_ops.clear();
683 // -----------------------------------------------------------------------------
684 void fillEntryAndDisable(ListBox& _rListBox,const String& _sEntry)
686 _rListBox.InsertEntry(_sEntry);
687 _rListBox.SelectEntryPos(0);
688 _rListBox.Disable();
690 // -----------------------------------------------------------------------------
691 void OTableListBoxControl::fillAndDisable(const TTableConnectionData::value_type& _pConnectionData)
693 fillEntryAndDisable(m_lmbLeftTable,_pConnectionData->getReferencingTable()->GetWinName());
694 fillEntryAndDisable(m_lmbRightTable,_pConnectionData->getReferencedTable()->GetWinName());
696 // -----------------------------------------------------------------------------
697 void OTableListBoxControl::Init(const TTableConnectionData::value_type& _pConnData)
699 m_pRC_Tables->Init(_pConnData);
701 // -----------------------------------------------------------------------------
702 void OTableListBoxControl::lateUIInit(Window* _pTableSeparator)
704 const sal_Int32 nDiff = LogicToPixel( Point(0,6), MAP_APPFONT ).Y();
705 Point aDlgPoint = LogicToPixel( Point(12,43), MAP_APPFONT );
706 if ( _pTableSeparator )
708 _pTableSeparator->SetZOrder(&m_lmbRightTable, WINDOW_ZORDER_BEHIND);
709 m_pRC_Tables->SetZOrder(_pTableSeparator, WINDOW_ZORDER_BEHIND);
710 _pTableSeparator->SetPosPixel(Point(0,m_aFL_InvolvedFields.GetPosPixel().Y()));
711 const Size aSize = _pTableSeparator->GetSizePixel();
712 aDlgPoint.Y() = _pTableSeparator->GetPosPixel().Y() + aSize.Height();
713 m_aFL_InvolvedFields.SetPosPixel(Point(m_aFL_InvolvedFields.GetPosPixel().X(),aDlgPoint.Y()));
714 aDlgPoint.Y() += nDiff + m_aFL_InvolvedFields.GetSizePixel().Height();
716 //////////////////////////////////////////////////////////////////////
717 // positing BrowseBox control
718 const Size aCurrentSize = GetSizePixel();
719 Size aDlgSize = LogicToPixel( Size(24,0), MAP_APPFONT );
720 aDlgSize.Width() = aCurrentSize.Width() - aDlgSize.Width();
721 aDlgSize.Height() = aCurrentSize.Height() - aDlgPoint.Y() - nDiff;
723 m_pRC_Tables->SetPosSizePixel( aDlgPoint, aDlgSize );
724 m_pRC_Tables->Show();
726 lateInit();
728 // -----------------------------------------------------------------------------
729 void OTableListBoxControl::lateInit()
731 m_pRC_Tables->lateInit();
733 // -----------------------------------------------------------------------------
734 sal_Bool OTableListBoxControl::SaveModified()
736 return m_pRC_Tables->SaveModified();
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 // -----------------------------------------------------------------------------
755 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */