Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "RelationControl.hxx"
21 : : #include "RelationControl.hrc"
22 : :
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>
37 : :
38 : : #include <algorithm>
39 : :
40 : : #define SOURCE_COLUMN 1
41 : : #define DEST_COLUMN 2
42 : :
43 : : namespace dbaui
44 : : {
45 : : using namespace ::com::sun::star::uno;
46 : : using namespace ::com::sun::star::beans;
47 : : using namespace ::com::sun::star::sdbc;
48 : : using namespace ::com::sun::star::sdbcx;
49 : : using namespace ::com::sun::star::container;
50 : : using namespace svt;
51 : :
52 : : typedef ::svt::EditBrowseBox ORelationControl_Base;
53 : : class ORelationControl : public ORelationControl_Base
54 : : {
55 : : friend class OTableListBoxControl;
56 : :
57 : : ::std::auto_ptr< ::svt::ListBoxControl> m_pListCell;
58 : : TTableConnectionData::value_type m_pConnData;
59 : : const OJoinTableView::OTableWindowMap* m_pTableMap;
60 : : OTableListBoxControl* m_pBoxControl;
61 : : long m_nDataPos;
62 : : Reference< XPropertySet> m_xSourceDef;
63 : : Reference< XPropertySet> m_xDestDef;
64 : :
65 : :
66 : : void fillListBox(const Reference< XPropertySet>& _xDest,long nRow,sal_uInt16 nColumnId);
67 : : /** returns the column id for the editbrowsebox
68 : : @param _nColId
69 : : the column id SOURCE_COLUMN or DEST_COLUMN
70 : :
71 : : @return the current column id eihter SOURCE_COLUMN or DEST_COLUMN depends on the connection data
72 : : */
73 : : sal_uInt16 getColumnIdent( sal_uInt16 _nColId ) const;
74 : : public:
75 : : ORelationControl( OTableListBoxControl* pParent,const OJoinTableView::OTableWindowMap* _pTableMap );
76 : : virtual ~ORelationControl();
77 : :
78 : : /** searches for a connection between these two tables
79 : : @param _pSource
80 : : the left table
81 : : @param _pDest
82 : : the right window
83 : : */
84 : : void setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest);
85 : :
86 : : /** allows to access the connection data from outside
87 : :
88 : : @return rthe connection data
89 : : */
90 : 0 : inline TTableConnectionData::value_type getData() const { return m_pConnData; }
91 : :
92 : : void lateInit();
93 : :
94 : : protected:
95 : : virtual void Resize();
96 : :
97 : : virtual long PreNotify(NotifyEvent& rNEvt );
98 : :
99 : : virtual sal_Bool IsTabAllowed(sal_Bool bForward) const;
100 : :
101 : : virtual void Init(const TTableConnectionData::value_type& _pConnData);
102 : 0 : virtual void Init() { ORelationControl_Base::Init(); }
103 : : virtual void InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol );
104 : : virtual ::svt::CellController* GetController( long nRow, sal_uInt16 nCol );
105 : : virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId ) const;
106 : : virtual sal_Bool SeekRow( long nRow );
107 : : virtual sal_Bool SaveModified();
108 : : virtual String GetCellText( long nRow, sal_uInt16 nColId ) const;
109 : :
110 : : virtual void CellModified();
111 : :
112 : : DECL_LINK( AsynchDeactivate, void* );
113 : : private:
114 : :
115 : : DECL_LINK( AsynchActivate, void* );
116 : :
117 : : };
118 : :
119 : : //========================================================================
120 : : // class ORelationControl
121 : : //========================================================================
122 : : DBG_NAME(ORelationControl)
123 : : //------------------------------------------------------------------------
124 : 0 : ORelationControl::ORelationControl( OTableListBoxControl* pParent ,const OJoinTableView::OTableWindowMap* _pTableMap)
125 : : :EditBrowseBox( pParent, EBBF_SMART_TAB_TRAVEL | EBBF_NOROWPICTURE, WB_TABSTOP | WB_BORDER | BROWSER_AUTOSIZE_LASTCOL)
126 : : ,m_pTableMap(_pTableMap)
127 : : ,m_pBoxControl(pParent)
128 : : ,m_xSourceDef( NULL )
129 [ # # ][ # # ]: 0 : ,m_xDestDef( NULL )
[ # # ]
130 : : {
131 : : DBG_CTOR(ORelationControl,NULL);
132 : 0 : }
133 : :
134 : : //------------------------------------------------------------------------
135 [ # # ][ # # ]: 0 : ORelationControl::~ORelationControl()
136 : : {
137 : : DBG_DTOR(ORelationControl,NULL);
138 [ # # ]: 0 : }
139 : :
140 : : //------------------------------------------------------------------------
141 : 0 : void ORelationControl::Init(const TTableConnectionData::value_type& _pConnData)
142 : : {
143 : : DBG_CHKTHIS(ORelationControl,NULL);
144 : :
145 : 0 : m_pConnData = _pConnData;
146 : : OSL_ENSURE(m_pConnData, "No data supplied!");
147 : :
148 : 0 : m_pConnData->normalizeLines();
149 : 0 : }
150 : : //------------------------------------------------------------------------------
151 : 0 : void ORelationControl::lateInit()
152 : : {
153 [ # # ]: 0 : if ( !m_pConnData.get() )
154 : 0 : return;
155 [ # # ][ # # ]: 0 : m_xSourceDef = m_pConnData->getReferencingTable()->getTable();
156 [ # # ][ # # ]: 0 : m_xDestDef = m_pConnData->getReferencedTable()->getTable();
157 : :
158 [ # # ]: 0 : if ( ColCount() == 0 )
159 : : {
160 [ # # ][ # # ]: 0 : InsertDataColumn( SOURCE_COLUMN, m_pConnData->getReferencingTable()->GetWinName(), 100);
[ # # ]
161 [ # # ][ # # ]: 0 : InsertDataColumn( DEST_COLUMN, m_pConnData->getReferencedTable()->GetWinName(), 100);
[ # # ]
162 : : // If the Defs do not yet exits, we need to set them with SetSource-/-DestDef
163 : :
164 [ # # ]: 0 : m_pListCell.reset( new ListBoxControl( &GetDataWindow() ) );
165 : :
166 : : //////////////////////////////////////////////////////////////////////
167 : : // set browse mode
168 : : SetMode( BROWSER_COLUMNSELECTION |
169 : : BROWSER_HLINESFULL |
170 : : BROWSER_VLINESFULL |
171 : : BROWSER_HIDECURSOR |
172 : : BROWSER_HIDESELECT |
173 : : BROWSER_AUTO_HSCROLL |
174 : 0 : BROWSER_AUTO_VSCROLL);
175 : : }
176 : : else
177 : : // not the first call
178 : 0 : RowRemoved(0, GetRowCount());
179 : :
180 : 0 : RowInserted(0, m_pConnData->GetConnLineDataList()->size() + 1, sal_True); // add one extra row
181 : : }
182 : : //------------------------------------------------------------------------------
183 : 0 : void ORelationControl::Resize()
184 : : {
185 : : DBG_CHKTHIS(ORelationControl,NULL);
186 : 0 : EditBrowseBox::Resize();
187 : 0 : long nOutputWidth = GetOutputSizePixel().Width();
188 : 0 : SetColumnWidth(1, (nOutputWidth / 2));
189 : 0 : SetColumnWidth(2, (nOutputWidth / 2));
190 : 0 : }
191 : :
192 : : //------------------------------------------------------------------------------
193 : 0 : long ORelationControl::PreNotify(NotifyEvent& rNEvt)
194 : : {
195 : : DBG_CHKTHIS(ORelationControl,NULL);
196 [ # # ][ # # ]: 0 : if (rNEvt.GetType() == EVENT_LOSEFOCUS && !HasChildPathFocus() )
[ # # ]
197 [ # # ]: 0 : PostUserEvent(LINK(this, ORelationControl, AsynchDeactivate));
198 [ # # ]: 0 : else if (rNEvt.GetType() == EVENT_GETFOCUS)
199 [ # # ]: 0 : PostUserEvent(LINK(this, ORelationControl, AsynchActivate));
200 : :
201 : 0 : return EditBrowseBox::PreNotify(rNEvt);
202 : : }
203 : :
204 : : //------------------------------------------------------------------------------
205 : 0 : IMPL_LINK_NOARG(ORelationControl, AsynchActivate)
206 : : {
207 : 0 : ActivateCell();
208 : 0 : return 0L;
209 : : }
210 : :
211 : : //------------------------------------------------------------------------------
212 : 0 : IMPL_LINK_NOARG(ORelationControl, AsynchDeactivate)
213 : : {
214 : 0 : DeactivateCell();
215 : 0 : return 0L;
216 : : }
217 : :
218 : : //------------------------------------------------------------------------------
219 : 0 : sal_Bool ORelationControl::IsTabAllowed(sal_Bool bForward) const
220 : : {
221 : : DBG_CHKTHIS(ORelationControl,NULL);
222 : 0 : long nRow = GetCurRow();
223 : 0 : sal_uInt16 nCol = GetCurColumnId();
224 : :
225 : 0 : sal_Bool bRet = !(( ( bForward && (nCol == DEST_COLUMN) && (nRow == GetRowCount() - 1)))
226 [ # # # # ]: 0 : || (!bForward && (nCol == SOURCE_COLUMN) && (nRow == 0)));
[ # # ][ # # ]
[ # # ][ # # ]
227 : :
228 [ # # ][ # # ]: 0 : return bRet && EditBrowseBox::IsTabAllowed(bForward);
229 : : }
230 : :
231 : : //------------------------------------------------------------------------------
232 : 0 : sal_Bool ORelationControl::SaveModified()
233 : : {
234 : : DBG_CHKTHIS(ORelationControl,NULL);
235 : 0 : sal_Int32 nRow = GetCurRow();
236 [ # # ]: 0 : if ( nRow != BROWSER_ENDOFSELECTION )
237 : : {
238 [ # # ]: 0 : String sFieldName(m_pListCell->GetSelectEntry());
239 : 0 : OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
240 [ # # ]: 0 : if ( pLines->size() <= static_cast<sal_uInt32>(nRow) )
241 : : {
242 [ # # ][ # # ]: 0 : pLines->push_back(new OConnectionLineData());
[ # # ][ # # ]
[ # # ]
243 : 0 : nRow = pLines->size() - 1;
244 : : }
245 : :
246 [ # # ]: 0 : OConnectionLineDataRef pConnLineData = (*pLines)[nRow];
247 : :
248 [ # # ]: 0 : switch( getColumnIdent( GetCurColumnId() ) )
[ # # # ]
249 : : {
250 : : case SOURCE_COLUMN:
251 [ # # ]: 0 : pConnLineData->SetSourceFieldName( sFieldName );
252 : 0 : break;
253 : : case DEST_COLUMN:
254 [ # # ]: 0 : pConnLineData->SetDestFieldName( sFieldName );
255 : 0 : break;
256 [ # # ][ # # ]: 0 : }
257 : : }
258 : :
259 : 0 : return sal_True;
260 : : }
261 : : //------------------------------------------------------------------------------
262 : 0 : sal_uInt16 ORelationControl::getColumnIdent( sal_uInt16 _nColId ) const
263 : : {
264 : 0 : sal_uInt16 nId = _nColId;
265 [ # # ][ # # ]: 0 : if ( m_pConnData->getReferencingTable() != m_pBoxControl->getReferencingTable() )
[ # # ][ # # ]
266 [ # # ]: 0 : nId = ( _nColId == SOURCE_COLUMN) ? DEST_COLUMN : SOURCE_COLUMN;
267 : 0 : return nId;
268 : : }
269 : :
270 : : //------------------------------------------------------------------------------
271 : 0 : String ORelationControl::GetCellText( long nRow, sal_uInt16 nColId ) const
272 : : {
273 : : DBG_CHKTHIS(ORelationControl,NULL);
274 : 0 : String sText;
275 [ # # ]: 0 : if ( m_pConnData->GetConnLineDataList()->size() > static_cast<size_t>(nRow) )
276 : : {
277 [ # # ]: 0 : OConnectionLineDataRef pConnLineData = (*m_pConnData->GetConnLineDataList())[nRow];
278 [ # # ]: 0 : switch( getColumnIdent( nColId ) )
[ # # # ]
279 : : {
280 : : case SOURCE_COLUMN:
281 [ # # ]: 0 : sText = pConnLineData->GetSourceFieldName();
282 : 0 : break;
283 : : case DEST_COLUMN:
284 [ # # ]: 0 : sText = pConnLineData->GetDestFieldName();
285 : 0 : break;
286 [ # # ]: 0 : }
287 : : }
288 : 0 : return sText;
289 : : }
290 : :
291 : : //------------------------------------------------------------------------------
292 : 0 : void ORelationControl::InitController( CellControllerRef& /*rController*/, long nRow, sal_uInt16 nColumnId )
293 : : {
294 : : DBG_CHKTHIS(ORelationControl,NULL);
295 : :
296 : 0 : rtl::OString sHelpId( HID_RELATIONDIALOG_LEFTFIELDCELL );
297 : :
298 : 0 : Reference< XPropertySet> xDef;
299 [ # # # ]: 0 : switch ( getColumnIdent(nColumnId) )
[ # # ]
300 : : {
301 : : case SOURCE_COLUMN:
302 [ # # ]: 0 : xDef = m_xSourceDef;
303 : 0 : sHelpId = HID_RELATIONDIALOG_LEFTFIELDCELL;
304 : 0 : break;
305 : : case DEST_COLUMN:
306 [ # # ]: 0 : xDef = m_xDestDef;
307 : 0 : sHelpId = HID_RELATIONDIALOG_RIGHTFIELDCELL;
308 : 0 : break;
309 : : default:
310 : : // ?????????
311 : 0 : break;
312 : : }
313 : :
314 [ # # ]: 0 : if ( xDef.is() )
315 : : {
316 [ # # ]: 0 : fillListBox(xDef,nRow,nColumnId);
317 [ # # ]: 0 : String sName = GetCellText( nRow, nColumnId );
318 [ # # ]: 0 : m_pListCell->SelectEntry( sName );
319 [ # # ][ # # ]: 0 : if ( m_pListCell->GetSelectEntry() != sName )
[ # # ][ # # ]
320 : : {
321 [ # # ]: 0 : m_pListCell->InsertEntry( sName );
322 [ # # ]: 0 : m_pListCell->SelectEntry( sName );
323 : : }
324 : :
325 [ # # ][ # # ]: 0 : m_pListCell->SetHelpId(sHelpId);
326 : 0 : }
327 : 0 : }
328 : :
329 : : //------------------------------------------------------------------------------
330 : 0 : CellController* ORelationControl::GetController( long /*nRow*/, sal_uInt16 /*nColumnId*/ )
331 : : {
332 : : DBG_CHKTHIS(ORelationControl,NULL);
333 [ # # ]: 0 : return new ListBoxCellController( m_pListCell.get() );
334 : : }
335 : :
336 : : //------------------------------------------------------------------------------
337 : 0 : sal_Bool ORelationControl::SeekRow( long nRow )
338 : : {
339 : : DBG_CHKTHIS(ORelationControl,NULL);
340 : 0 : m_nDataPos = nRow;
341 : 0 : return sal_True;
342 : : }
343 : :
344 : : //------------------------------------------------------------------------------
345 : 0 : void ORelationControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
346 : : {
347 : : DBG_CHKTHIS(ORelationControl,NULL);
348 [ # # ]: 0 : String aText =const_cast< ORelationControl*>(this)->GetCellText( m_nDataPos, nColumnId );
349 : :
350 : 0 : Point aPos( rRect.TopLeft() );
351 [ # # ][ # # ]: 0 : Size aTextSize( GetDataWindow().GetTextHeight(),GetDataWindow().GetTextWidth( aText ));
352 : :
353 [ # # # # : 0 : if( aPos.X() < rRect.Right() || aPos.X() + aTextSize.Width() > rRect.Right() ||
# # ][ # # ]
[ # # ]
354 : 0 : aPos.Y() < rRect.Top() || aPos.Y() + aTextSize.Height() > rRect.Bottom() )
355 [ # # ][ # # ]: 0 : rDev.SetClipRegion( rRect );
[ # # ]
356 : :
357 [ # # ]: 0 : rDev.DrawText( aPos, aText );
358 : :
359 [ # # ]: 0 : if( rDev.IsClipRegion() )
360 [ # # ][ # # ]: 0 : rDev.SetClipRegion();
361 : 0 : }
362 : : // -----------------------------------------------------------------------------
363 : 0 : void ORelationControl::fillListBox(const Reference< XPropertySet>& _xDest,long /*_nRow*/,sal_uInt16 /*nColumnId*/)
364 : : {
365 : 0 : m_pListCell->Clear();
366 : : try
367 : : {
368 [ # # ]: 0 : if ( _xDest.is() )
369 : : {
370 : : //sal_Int32 nRows = GetRowCount();
371 [ # # ]: 0 : Reference<XColumnsSupplier> xSup(_xDest,UNO_QUERY);
372 [ # # ][ # # ]: 0 : Reference<XNameAccess> xColumns = xSup->getColumns();
373 [ # # ][ # # ]: 0 : Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
374 : 0 : const ::rtl::OUString* pIter = aNames.getConstArray();
375 : 0 : const ::rtl::OUString* pEnd = pIter + aNames.getLength();
376 [ # # ]: 0 : for(;pIter != pEnd;++pIter)
377 : : {
378 [ # # ][ # # ]: 0 : m_pListCell->InsertEntry( *pIter );
[ # # ]
379 : : }
380 [ # # ][ # # ]: 0 : m_pListCell->InsertEntry(String(), 0);
[ # # ][ # # ]
[ # # ]
381 : : }
382 : : }
383 : 0 : catch( const Exception& )
384 : : {
385 : : DBG_UNHANDLED_EXCEPTION();
386 : : }
387 : 0 : }
388 : : // -----------------------------------------------------------------------------
389 : 0 : void ORelationControl::setWindowTables(const OTableWindow* _pSource,const OTableWindow* _pDest)
390 : : {
391 : : // If I edit here, hide
392 : 0 : sal_Bool bWasEditing = IsEditing();
393 [ # # ]: 0 : if ( bWasEditing )
394 : 0 : DeactivateCell();
395 : :
396 [ # # ][ # # ]: 0 : if ( _pSource && _pDest )
397 : : {
398 [ # # ]: 0 : m_xSourceDef = _pSource->GetTable();
399 [ # # ][ # # ]: 0 : SetColumnTitle(1, _pSource->GetName());
[ # # ]
400 : :
401 : :
402 [ # # ]: 0 : m_xDestDef = _pDest->GetTable();
403 [ # # ][ # # ]: 0 : SetColumnTitle(2, _pDest->GetName());
[ # # ]
404 : :
405 : 0 : const OJoinTableView* pView = _pSource->getTableView();
406 : 0 : OTableConnection* pConn = pView->GetTabConn(_pSource,_pDest);
407 [ # # ][ # # ]: 0 : if ( pConn && !m_pConnData->GetConnLineDataList()->empty() )
[ # # ]
408 : : {
409 [ # # ]: 0 : m_pConnData->CopyFrom(*pConn->GetData());
410 : 0 : m_pBoxControl->getContainer()->notifyConnectionChange();
411 : : }
412 : : else
413 : : {
414 : : // no connection found so we clear our data
415 : 0 : OConnectionLineDataVec* pLines = m_pConnData->GetConnLineDataList();
416 : : ::std::for_each(pLines->begin(),
417 : : pLines->end(),
418 : 0 : OUnaryRefFunctor<OConnectionLineData>( ::std::mem_fun(&OConnectionLineData::Reset))
419 [ # # ]: 0 : );
420 : :
421 [ # # ]: 0 : m_pConnData->setReferencingTable(_pSource->GetData());
422 [ # # ]: 0 : m_pConnData->setReferencedTable(_pDest->GetData());
423 : : }
424 : 0 : m_pConnData->normalizeLines();
425 : :
426 : : }
427 : : // Repaint
428 : 0 : Invalidate();
429 : :
430 [ # # ]: 0 : if ( bWasEditing )
431 : : {
432 : 0 : GoToRow(0);
433 : 0 : ActivateCell();
434 : : }
435 : 0 : }
436 : : //------------------------------------------------------------------------
437 : 0 : void ORelationControl::CellModified()
438 : : {
439 : : DBG_CHKTHIS(ORelationControl,NULL);
440 : 0 : EditBrowseBox::CellModified();
441 : 0 : SaveModified();
442 : 0 : static_cast<OTableListBoxControl*>(GetParent())->NotifyCellChange();
443 : 0 : }
444 : : //========================================================================
445 : : // class OTableListBoxControl
446 : : DBG_NAME(OTableListBoxControl)
447 : :
448 : : //========================================================================
449 : :
450 : 0 : OTableListBoxControl::OTableListBoxControl( Window* _pParent
451 : : ,const ResId& _rResId
452 : : ,const OJoinTableView::OTableWindowMap* _pTableMap
453 : : ,IRelationControlInterface* _pParentDialog)
454 : : : Window(_pParent,_rResId)
455 : 0 : , m_aFL_InvolvedTables( this, ResId(FL_INVOLVED_TABLES,*_rResId.GetResMgr()))
456 : 0 : , m_lmbLeftTable( this, ResId(LB_LEFT_TABLE,*_rResId.GetResMgr()))
457 : 0 : , m_lmbRightTable( this, ResId(LB_RIGHT_TABLE,*_rResId.GetResMgr()))
458 : 0 : , m_aFL_InvolvedFields( this, ResId(FL_INVOLVED_FIELDS,*_rResId.GetResMgr()))
459 : : , m_pTableMap(_pTableMap)
460 [ # # # # : 0 : , m_pParentDialog(_pParentDialog)
# # # # ]
[ # # ][ # # ]
461 : : {
462 [ # # ][ # # ]: 0 : m_pRC_Tables = new ORelationControl( this,m_pTableMap );
463 [ # # ]: 0 : m_pRC_Tables->SetHelpId(HID_RELDLG_KEYFIELDS);
464 [ # # ]: 0 : m_pRC_Tables->Init( );
465 [ # # ]: 0 : m_pRC_Tables->SetZOrder(&m_lmbRightTable, WINDOW_ZORDER_BEHIND);
466 : :
467 [ # # ]: 0 : lateUIInit();
468 : :
469 [ # # ]: 0 : Link aLink(LINK(this, OTableListBoxControl, OnTableChanged));
470 : 0 : m_lmbLeftTable.SetSelectHdl(aLink);
471 : 0 : m_lmbRightTable.SetSelectHdl(aLink);
472 : :
473 [ # # ]: 0 : FreeResource();
474 : : DBG_CTOR(OTableListBoxControl,NULL);
475 : 0 : }
476 : : // -----------------------------------------------------------------------------
477 [ # # ][ # # ]: 0 : OTableListBoxControl::~OTableListBoxControl()
[ # # ][ # # ]
[ # # ][ # # ]
478 : : {
479 : 0 : ORelationControl* pTemp = m_pRC_Tables;
480 : 0 : m_pRC_Tables = NULL;
481 [ # # ][ # # ]: 0 : delete pTemp;
482 : : DBG_DTOR(OTableListBoxControl,NULL);
483 [ # # ]: 0 : }
484 : : // -----------------------------------------------------------------------------
485 : 0 : void OTableListBoxControl::fillListBoxes()
486 : : {
487 : : OSL_ENSURE( !m_pTableMap->empty(), "OTableListBoxControl::fillListBoxes: no table window!");
488 : 0 : OTableWindow* pInitialLeft = NULL;
489 : 0 : OTableWindow* pInitialRight = NULL;
490 : :
491 : : // Collect the names of all TabWins
492 : 0 : OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
493 : 0 : OJoinTableView::OTableWindowMap::const_iterator aEnd = m_pTableMap->end();
494 [ # # ]: 0 : for(;aIter != aEnd;++aIter)
495 : : {
496 [ # # ][ # # ]: 0 : m_lmbLeftTable.InsertEntry(aIter->first);
[ # # ]
497 [ # # ][ # # ]: 0 : m_lmbRightTable.InsertEntry(aIter->first);
[ # # ]
498 : :
499 [ # # ]: 0 : if (!pInitialLeft)
500 : : {
501 : 0 : pInitialLeft = aIter->second;
502 [ # # ]: 0 : m_strCurrentLeft = aIter->first;
503 : : }
504 [ # # ]: 0 : else if (!pInitialRight)
505 : : {
506 : 0 : pInitialRight = aIter->second;
507 [ # # ]: 0 : m_strCurrentRight = aIter->first;
508 : : }
509 : : }
510 : :
511 [ # # ]: 0 : if ( !pInitialRight )
512 : : {
513 : 0 : pInitialRight = pInitialLeft;
514 [ # # ]: 0 : m_strCurrentRight = m_strCurrentLeft;
515 : : }
516 : :
517 : : // The corresponding Defs for my Controls
518 [ # # ]: 0 : m_pRC_Tables->setWindowTables(pInitialLeft,pInitialRight);
519 : :
520 : : // The table selected in a ComboBox must not be available in the other
521 : :
522 [ # # ]: 0 : if ( m_pTableMap->size() > 2 )
523 : : {
524 [ # # ]: 0 : m_lmbLeftTable.RemoveEntry(m_strCurrentRight);
525 [ # # ]: 0 : m_lmbRightTable.RemoveEntry(m_strCurrentLeft);
526 : : }
527 : :
528 : : // Select the first one on the left side and on the right side,
529 : : // select the second one
530 [ # # ]: 0 : m_lmbLeftTable.SelectEntry(m_strCurrentLeft);
531 [ # # ]: 0 : m_lmbRightTable.SelectEntry(m_strCurrentRight);
532 : :
533 [ # # ]: 0 : m_lmbLeftTable.GrabFocus();
534 : 0 : }
535 : : // -----------------------------------------------------------------------------
536 : 0 : IMPL_LINK( OTableListBoxControl, OnTableChanged, ListBox*, pListBox )
537 : : {
538 [ # # ]: 0 : String strSelected(pListBox->GetSelectEntry());
539 : 0 : OTableWindow* pLeft = NULL;
540 : 0 : OTableWindow* pRight = NULL;
541 : :
542 : : // Special treatment: If there are only two tables, we need to switch the other one too when changing in a LB
543 [ # # ]: 0 : if ( m_pTableMap->size() == 2 )
544 : : {
545 : : ListBox* pOther;
546 [ # # ]: 0 : if ( pListBox == &m_lmbLeftTable )
547 : 0 : pOther = &m_lmbRightTable;
548 : : else
549 : 0 : pOther = &m_lmbLeftTable;
550 [ # # ][ # # ]: 0 : pOther->SelectEntryPos(1 - pOther->GetSelectEntryPos());
551 : :
552 : 0 : OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->begin();
553 : 0 : OTableWindow* pFirst = aIter->second;
554 : 0 : ++aIter;
555 : 0 : OTableWindow* pSecond = aIter->second;
556 : :
557 [ # # ][ # # ]: 0 : if ( m_lmbLeftTable.GetSelectEntry() == String(pFirst->GetName()) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
558 : : {
559 : 0 : pLeft = pFirst;
560 : 0 : pRight = pSecond;
561 : : }
562 : : else
563 : : {
564 : 0 : pLeft = pSecond;
565 : 0 : pRight = pFirst;
566 : : }
567 : : }
568 : : else
569 : : {
570 : : // First we need the TableDef to the Table and with it the TabWin
571 [ # # ][ # # ]: 0 : OJoinTableView::OTableWindowMap::const_iterator aFind = m_pTableMap->find(strSelected);
572 : 0 : OTableWindow* pLoop = NULL;
573 [ # # ]: 0 : if( aFind != m_pTableMap->end() )
574 : 0 : pLoop = aFind->second;
575 : : OSL_ENSURE(pLoop != NULL, "ORelationDialog::OnTableChanged: invalid ListBox entry!");
576 : : // We need to find strSelect, because we filled the ListBoxes with the table names with which we compare now
577 [ # # ]: 0 : if (pListBox == &m_lmbLeftTable)
578 : : {
579 : : // Insert the previously selected Entry on the left side on the right side
580 [ # # ]: 0 : m_lmbRightTable.InsertEntry(m_strCurrentLeft);
581 : : // Remove the currently selected Entry
582 [ # # ]: 0 : m_lmbRightTable.RemoveEntry(strSelected);
583 [ # # ]: 0 : m_strCurrentLeft = strSelected;
584 : :
585 : 0 : pLeft = pLoop;
586 : :
587 [ # # ][ # # ]: 0 : OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_lmbRightTable.GetSelectEntry());
[ # # ][ # # ]
588 : : OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
589 [ # # ]: 0 : if ( aIter != m_pTableMap->end() )
590 : 0 : pRight = aIter->second;
591 : :
592 [ # # ]: 0 : m_lmbLeftTable.GrabFocus();
593 : : }
594 : : else
595 : : {
596 : : // Insert the previously selected Entry on the right side on the left side
597 [ # # ]: 0 : m_lmbLeftTable.InsertEntry(m_strCurrentRight);
598 : : // Remove the currently selected Entry
599 [ # # ]: 0 : m_lmbLeftTable.RemoveEntry(strSelected);
600 [ # # ]: 0 : m_strCurrentRight = strSelected;
601 : :
602 : 0 : pRight = pLoop;
603 [ # # ][ # # ]: 0 : OJoinTableView::OTableWindowMap::const_iterator aIter = m_pTableMap->find(m_lmbLeftTable.GetSelectEntry());
[ # # ][ # # ]
604 : : OSL_ENSURE( aIter != m_pTableMap->end(), "Invalid name");
605 [ # # ]: 0 : if ( aIter != m_pTableMap->end() )
606 : 0 : pLeft = aIter->second;
607 : : }
608 : : }
609 : :
610 [ # # ]: 0 : pListBox->GrabFocus();
611 : :
612 [ # # ]: 0 : m_pRC_Tables->setWindowTables(pLeft,pRight);
613 : :
614 [ # # ]: 0 : NotifyCellChange();
615 [ # # ]: 0 : return 0;
616 : : }
617 : : // -----------------------------------------------------------------------------
618 : 0 : void OTableListBoxControl::NotifyCellChange()
619 : : {
620 : : // Enable/disable the OK button, depending on having a valid situation
621 [ # # ]: 0 : TTableConnectionData::value_type pConnData = m_pRC_Tables->getData();
622 : 0 : const OConnectionLineDataVec* pLines = pConnData->GetConnLineDataList();
623 [ # # ]: 0 : m_pParentDialog->setValid(!pLines->empty());
624 : :
625 [ # # ][ # # ]: 0 : if ( pLines->size() >= static_cast<sal_uInt32>(m_pRC_Tables->GetRowCount()) )
626 : : {
627 [ # # ]: 0 : m_pRC_Tables->DeactivateCell();
628 [ # # ][ # # ]: 0 : m_pRC_Tables->RowInserted(m_pRC_Tables->GetRowCount(), pLines->size() - static_cast<sal_uInt32>(m_pRC_Tables->GetRowCount()) + 1, sal_True);
[ # # ]
629 [ # # ]: 0 : m_pRC_Tables->ActivateCell();
630 [ # # ]: 0 : }
631 : 0 : }
632 : : // -----------------------------------------------------------------------------
633 : 0 : void fillEntryAndDisable(ListBox& _rListBox,const String& _sEntry)
634 : : {
635 : 0 : _rListBox.InsertEntry(_sEntry);
636 : 0 : _rListBox.SelectEntryPos(0);
637 : 0 : _rListBox.Disable();
638 : 0 : }
639 : : // -----------------------------------------------------------------------------
640 : 0 : void OTableListBoxControl::fillAndDisable(const TTableConnectionData::value_type& _pConnectionData)
641 : : {
642 [ # # ][ # # ]: 0 : fillEntryAndDisable(m_lmbLeftTable,_pConnectionData->getReferencingTable()->GetWinName());
[ # # ]
643 [ # # ][ # # ]: 0 : fillEntryAndDisable(m_lmbRightTable,_pConnectionData->getReferencedTable()->GetWinName());
[ # # ]
644 : 0 : }
645 : : // -----------------------------------------------------------------------------
646 : 0 : void OTableListBoxControl::Init(const TTableConnectionData::value_type& _pConnData)
647 : : {
648 : 0 : m_pRC_Tables->Init(_pConnData);
649 : 0 : }
650 : : // -----------------------------------------------------------------------------
651 : 0 : void OTableListBoxControl::lateUIInit(Window* _pTableSeparator)
652 : : {
653 [ # # ][ # # ]: 0 : const sal_Int32 nDiff = LogicToPixel( Point(0,6), MAP_APPFONT ).Y();
[ # # ]
654 [ # # ][ # # ]: 0 : Point aDlgPoint = LogicToPixel( Point(12,43), MAP_APPFONT );
[ # # ]
655 [ # # ]: 0 : if ( _pTableSeparator )
656 : : {
657 [ # # ]: 0 : _pTableSeparator->SetZOrder(&m_lmbRightTable, WINDOW_ZORDER_BEHIND);
658 [ # # ]: 0 : m_pRC_Tables->SetZOrder(_pTableSeparator, WINDOW_ZORDER_BEHIND);
659 [ # # ][ # # ]: 0 : _pTableSeparator->SetPosPixel(Point(0,m_aFL_InvolvedFields.GetPosPixel().Y()));
660 [ # # ]: 0 : const Size aSize = _pTableSeparator->GetSizePixel();
661 [ # # ]: 0 : aDlgPoint.Y() = _pTableSeparator->GetPosPixel().Y() + aSize.Height();
662 [ # # ][ # # ]: 0 : m_aFL_InvolvedFields.SetPosPixel(Point(m_aFL_InvolvedFields.GetPosPixel().X(),aDlgPoint.Y()));
663 [ # # ]: 0 : aDlgPoint.Y() += nDiff + m_aFL_InvolvedFields.GetSizePixel().Height();
664 : : }
665 : : //////////////////////////////////////////////////////////////////////
666 : : // positing BrowseBox control
667 [ # # ]: 0 : const Size aCurrentSize = GetSizePixel();
668 [ # # ][ # # ]: 0 : Size aDlgSize = LogicToPixel( Size(24,0), MAP_APPFONT );
[ # # ]
669 : 0 : aDlgSize.Width() = aCurrentSize.Width() - aDlgSize.Width();
670 : 0 : aDlgSize.Height() = aCurrentSize.Height() - aDlgPoint.Y() - nDiff;
671 : :
672 [ # # ]: 0 : m_pRC_Tables->SetPosSizePixel( aDlgPoint, aDlgSize );
673 [ # # ]: 0 : m_pRC_Tables->Show();
674 : :
675 [ # # ]: 0 : lateInit();
676 : 0 : }
677 : : // -----------------------------------------------------------------------------
678 : 0 : void OTableListBoxControl::lateInit()
679 : : {
680 : 0 : m_pRC_Tables->lateInit();
681 : 0 : }
682 : : // -----------------------------------------------------------------------------
683 : 0 : sal_Bool OTableListBoxControl::SaveModified()
684 : : {
685 : 0 : sal_Bool bRet = m_pRC_Tables->SaveModified();
686 [ # # ]: 0 : m_pRC_Tables->getData()->normalizeLines();
687 : 0 : return bRet;
688 : : }
689 : : // -----------------------------------------------------------------------------
690 : 0 : TTableWindowData::value_type OTableListBoxControl::getReferencingTable() const
691 : : {
692 [ # # ]: 0 : return m_pRC_Tables->getData()->getReferencingTable();
693 : : }
694 : : // -----------------------------------------------------------------------------
695 : 0 : void OTableListBoxControl::enableRelation(bool _bEnable)
696 : : {
697 [ # # ]: 0 : if ( !_bEnable )
698 [ # # ]: 0 : PostUserEvent(LINK(m_pRC_Tables, ORelationControl, AsynchDeactivate));
699 : 0 : m_pRC_Tables->Enable(_bEnable);
700 : :
701 : 0 : }
702 : : // -----------------------------------------------------------------------------
703 : : }
704 : : // -----------------------------------------------------------------------------
705 : :
706 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|