update dev300-m58
[ooovba.git] / dbaccess / source / ui / querydesign / TableWindow.cxx
blob8f2b134371f280bf679df456a7ec79d43cfd475e
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: TableWindow.cxx,v $
10 * $Revision: 1.41.26.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_TABLEWINDOW_HXX
34 #include "TableWindow.hxx"
35 #endif
36 #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
37 #include "TableWindowListBox.hxx"
38 #endif
39 #ifndef DBAUI_QUERYTABLEVIEW_HXX
40 #include "QueryTableView.hxx"
41 #endif
42 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
43 #include "QueryDesignView.hxx"
44 #endif
45 #ifndef DBAUI_TABLEWINDOWDATA_HXX
46 #include "TableWindowData.hxx"
47 #endif
48 #ifndef DBACCESS_IMAGEPROVIDER_HXX
49 #include "imageprovider.hxx"
50 #endif
51 #ifndef _TOOLS_DEBUG_HXX
52 #include <tools/debug.hxx>
53 #endif
54 #ifndef TOOLS_DIAGNOSE_EX_H
55 #include <tools/diagnose_ex.h>
56 #endif
57 #ifndef _SV_SVAPP_HXX
58 #include <vcl/svapp.hxx>
59 #endif
60 #ifndef _SV_WALL_HXX
61 #include <vcl/wall.hxx>
62 #endif
64 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
65 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
66 #include <com/sun/star/sdbcx/KeyType.hpp>
67 #include <com/sun/star/container/XNameAccess.hpp>
68 #include <com/sun/star/beans/XPropertySet.hpp>
69 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
70 #include <com/sun/star/accessibility/AccessibleRole.hpp>
71 #include "querycontroller.hxx"
72 #include "dbu_qry.hrc"
73 #include "dbustrings.hrc"
74 #include "Query.hrc"
75 #include <comphelper/extract.hxx>
76 #include "UITools.hxx"
77 #include "TableWindowAccess.hxx"
78 #include "browserids.hxx"
81 using namespace dbaui;
82 using namespace ::utl;
83 using namespace ::com::sun::star;
84 using namespace ::com::sun::star::sdb;
85 using namespace ::com::sun::star::sdbc;
86 using namespace ::com::sun::star::sdbcx;
87 using namespace ::com::sun::star::uno;
88 using namespace ::com::sun::star::beans;
89 using namespace ::com::sun::star::container;
90 using namespace ::com::sun::star::lang;
91 using namespace ::com::sun::star::accessibility;
93 #define TABWIN_SIZING_AREA 4
94 #define LISTBOX_SCROLLING_AREA 6
95 #define SCROLLING_TIMESPAN 500
97 #define TABWIN_WIDTH_MIN 90
98 #define TABWIN_HEIGHT_MIN 80
100 //========================================================================
101 // class OTableWindow
102 //========================================================================
103 DBG_NAME(OTableWindow)
104 //------------------------------------------------------------------------------
105 OTableWindow::OTableWindow( Window* pParent, const TTableWindowData::value_type& pTabWinData )
106 : ::comphelper::OContainerListener(m_aMutex)
107 ,Window( pParent, WB_3DLOOK|WB_MOVEABLE )
108 ,m_aTypeImage( this )
109 ,m_aTitle( this )
110 ,m_pListBox(NULL)
111 ,m_pAccessible(NULL)
112 ,m_pData( pTabWinData )
113 ,m_nMoveCount(0)
114 ,m_nMoveIncrement(1)
115 ,m_nSizingFlags( SIZING_NONE )
116 ,m_bActive( FALSE )
118 DBG_CTOR(OTableWindow,NULL);
120 // Position und Groesse bestimmen
121 if( GetData()->HasPosition() )
122 SetPosPixel( GetData()->GetPosition() );
124 if( GetData()->HasSize() )
125 SetSizePixel( GetData()->GetSize() );
127 // Hintergrund setzen
128 const StyleSettings& aSystemStyle = Application::GetSettings().GetStyleSettings();
129 SetBackground(Wallpaper(aSystemStyle.GetFaceColor()));
130 // und Textfarbe (obwohl ich eigentlich keinen Text habe, aber wer weiss, was
131 // abgeleitete Klassen machen)
132 SetTextColor(aSystemStyle.GetButtonTextColor());
134 EnableClipSiblings();
137 //------------------------------------------------------------------------------
138 OTableWindow::~OTableWindow()
140 DBG_DTOR(OTableWindow,NULL);
142 if (m_pListBox)
144 OSL_ENSURE(m_pListBox->GetEntryCount()==0,"Forgot to call EmptyListbox()!");
145 ::std::auto_ptr<Window> aTemp(m_pListBox);
146 m_pListBox = NULL;
147 } // if (m_pListBox)
148 if ( m_pContainerListener.is() )
149 m_pContainerListener->dispose();
151 m_pAccessible = NULL;
153 // -----------------------------------------------------------------------------
154 const OJoinTableView* OTableWindow::getTableView() const
156 OSL_ENSURE(static_cast<OJoinTableView*>(GetParent()),"No OJoinTableView!");
157 return static_cast<OJoinTableView*>(GetParent());
159 // -----------------------------------------------------------------------------
160 OJoinTableView* OTableWindow::getTableView()
162 OSL_ENSURE(static_cast<OJoinTableView*>(GetParent()),"No OJoinTableView!");
163 return static_cast<OJoinTableView*>(GetParent());
165 // -----------------------------------------------------------------------------
166 OJoinDesignView* OTableWindow::getDesignView()
168 OSL_ENSURE(static_cast<OJoinDesignView*>(GetParent()->GetParent()->GetParent()),"No OJoinDesignView!");
169 return static_cast<OJoinDesignView*>(GetParent()->GetParent()->GetParent());
171 //------------------------------------------------------------------------------
172 void OTableWindow::SetPosPixel( const Point& rNewPos )
174 Point aNewPosData = rNewPos + getTableView()->GetScrollOffset();
175 GetData()->SetPosition( aNewPosData );
176 Window::SetPosPixel( rNewPos );
179 //------------------------------------------------------------------------------
180 void OTableWindow::SetSizePixel( const Size& rNewSize )
182 Size aOutSize(rNewSize);
183 if( aOutSize.Width() < TABWIN_WIDTH_MIN )
184 aOutSize.Width() = TABWIN_WIDTH_MIN;
185 if( aOutSize.Height() < TABWIN_HEIGHT_MIN )
186 aOutSize.Height() = TABWIN_HEIGHT_MIN;
188 GetData()->SetSize( aOutSize );
189 Window::SetSizePixel( aOutSize );
191 //------------------------------------------------------------------------------
192 void OTableWindow::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
194 SetPosPixel( rNewPos );
195 SetSizePixel( rNewSize );
197 //------------------------------------------------------------------------------
198 OTableWindowListBox* OTableWindow::CreateListBox()
200 return new OTableWindowListBox(this);
203 //------------------------------------------------------------------------------
204 BOOL OTableWindow::FillListBox()
206 m_pListBox->Clear();
207 if ( !m_pContainerListener.is() )
209 Reference< XContainer> xContainer(m_pData->getColumns(),UNO_QUERY);
210 if ( xContainer.is() )
211 m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer);
213 // mark all primary keys with special image
214 ModuleRes TmpRes(isHiContrast(m_pListBox) ? IMG_JOINS_H : IMG_JOINS);
215 ImageList aImageList(TmpRes);
216 Image aPrimKeyImage = aImageList.GetImage(IMG_PRIMARY_KEY);
218 if (GetData()->IsShowAll())
220 SvLBoxEntry* pEntry = m_pListBox->InsertEntry( ::rtl::OUString::createFromAscii("*") );
221 pEntry->SetUserData( createUserData(NULL,false) );
224 Reference<XNameAccess> xPKeyColumns;
227 // first we need the keys from the table
228 Reference< XIndexAccess> xKeyIndex = m_pData->getKeys();
229 // search the one and only primary key
230 if ( xKeyIndex.is() )
232 Reference<XColumnsSupplier> xColumnsSupplier;
233 for(sal_Int32 i=0;i< xKeyIndex->getCount();++i)
235 Reference<XPropertySet> xProp;
236 xKeyIndex->getByIndex(i) >>= xProp;
237 if ( xProp.is() )
239 sal_Int32 nKeyType = 0;
240 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
241 if(KeyType::PRIMARY == nKeyType)
243 xColumnsSupplier.set(xProp,UNO_QUERY);
244 break;
248 if ( xColumnsSupplier.is() )
249 xPKeyColumns = xColumnsSupplier->getColumns();
252 catch(Exception&)
254 OSL_ENSURE(0,"Exception occured!");
258 Reference< XNameAccess > xColumns = m_pData->getColumns();
259 if( xColumns.is() )
261 Sequence< ::rtl::OUString> aColumns = xColumns->getElementNames();
262 const ::rtl::OUString* pIter = aColumns.getConstArray();
263 const ::rtl::OUString* pEnd = pIter + aColumns.getLength();
265 SvLBoxEntry* pEntry = NULL;
266 for (; pIter != pEnd; ++pIter)
268 bool bPrimaryKeyColumn = xPKeyColumns.is() && xPKeyColumns->hasByName( *pIter );
269 // is this column in the primary key
270 if ( bPrimaryKeyColumn )
271 pEntry = m_pListBox->InsertEntry(*pIter, aPrimKeyImage, aPrimKeyImage);
272 else
273 pEntry = m_pListBox->InsertEntry(*pIter);
275 Reference<XPropertySet> xColumn(xColumns->getByName(*pIter),UNO_QUERY);
276 if ( xColumn.is() )
277 pEntry->SetUserData( createUserData(xColumn,bPrimaryKeyColumn) );
281 catch(Exception&)
283 OSL_ENSURE(0,"Exception occured!");
286 return TRUE;
288 // -----------------------------------------------------------------------------
289 void* OTableWindow::createUserData(const Reference< XPropertySet>& /*_xColumn*/,bool /*_bPrimaryKey*/)
291 return NULL;
293 // -----------------------------------------------------------------------------
294 void OTableWindow::deleteUserData(void*& _pUserData)
296 OSL_ENSURE(!_pUserData,"INVALID call. Need to delete the userclass!");
297 _pUserData = NULL;
299 //------------------------------------------------------------------------------
300 void OTableWindow::clearListBox()
302 if ( m_pListBox )
304 SvLBoxEntry* pEntry = m_pListBox->First();
306 while(pEntry)
308 void* pUserData = pEntry->GetUserData();
309 deleteUserData(pUserData);
310 SvLBoxEntry* pNextEntry = m_pListBox->Next(pEntry);
311 m_pListBox->GetModel()->Remove(pEntry);
312 pEntry = pNextEntry;
317 //------------------------------------------------------------------------------
318 void OTableWindow::impl_updateImage()
320 ImageProvider aImageProvider( getDesignView()->getController().getConnection() );
322 Image aImage, aImageHC;
323 aImageProvider.getImages( GetComposedName(), m_pData->isQuery() ? DatabaseObject::QUERY : DatabaseObject::TABLE, aImage, aImageHC );
325 if ( !aImage || !aImageHC )
327 OSL_ENSURE( false, "OTableWindow::impl_updateImage: no images!" );
328 return;
331 m_aTypeImage.SetModeImage( aImage, BMP_COLOR_NORMAL );
332 m_aTypeImage.SetModeImage( aImageHC, BMP_COLOR_HIGHCONTRAST );
333 m_aTypeImage.Show();
336 //------------------------------------------------------------------------------
337 BOOL OTableWindow::Init()
339 // create list box if necessary
340 if ( !m_pListBox )
342 m_pListBox = CreateListBox();
343 DBG_ASSERT( m_pListBox != NULL, "OTableWindow::Init() : CreateListBox hat NULL geliefert !" );
344 m_pListBox->SetSelectionMode( MULTIPLE_SELECTION );
347 // Titel setzen
348 m_aTitle.SetText( m_pData->GetWinName() );
349 m_aTitle.Show();
351 m_pListBox->Show();
353 // die Felder in die ListBox eintragen
354 clearListBox();
355 BOOL bSuccess = FillListBox();
356 if ( bSuccess )
357 m_pListBox->SelectAll( FALSE );
359 impl_updateImage();
361 return bSuccess;
363 //------------------------------------------------------------------------------
364 void OTableWindow::DataChanged(const DataChangedEvent& rDCEvt)
366 if (rDCEvt.GetType() == DATACHANGED_SETTINGS)
368 // nehmen wir den worst-case an : die Farben haben sich geaendert, also
369 // mich anpassen
370 const StyleSettings& aSystemStyle = Application::GetSettings().GetStyleSettings();
371 SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
372 SetTextColor(aSystemStyle.GetButtonTextColor());
375 //------------------------------------------------------------------------------
376 void OTableWindow::Paint( const Rectangle& rRect )
378 Rectangle aRect( Point(0,0), GetOutputSizePixel() );
379 Window::Paint( rRect );
380 Draw3DBorder( aRect );
383 //------------------------------------------------------------------------------
384 void OTableWindow::Draw3DBorder(const Rectangle& rRect)
386 // die Style-Settings des Systems fuer meine Farben
387 const StyleSettings& aSystemStyle = Application::GetSettings().GetStyleSettings();
389 // Schwarze Linie unten und rechts
390 SetLineColor(aSystemStyle.GetDarkShadowColor());
391 DrawLine( rRect.BottomLeft(), rRect.BottomRight() );
392 DrawLine( rRect.BottomRight(), rRect.TopRight() );
394 // Dunkelgraue Linie ueber der schwarzen
395 SetLineColor(aSystemStyle.GetShadowColor());
396 Point aEHvector(1,1);
397 DrawLine( rRect.BottomLeft()+Point(1,-1), rRect.BottomRight() - aEHvector );
398 DrawLine( rRect.BottomRight() - aEHvector, rRect.TopRight()+Point(-1,1) );
400 // Hellgraue Linie links und oben
401 SetLineColor(aSystemStyle.GetLightColor());
402 DrawLine( rRect.BottomLeft()+Point(1,-2), rRect.TopLeft() + aEHvector );
403 DrawLine( rRect.TopLeft() + aEHvector, rRect.TopRight()+Point(-2,1) );
405 // -----------------------------------------------------------------------------
406 Rectangle OTableWindow::getSizingRect(const Point& _rPos,const Size& _rOutputSize) const
408 Rectangle aSizingRect = Rectangle( GetPosPixel(), GetSizePixel() );
409 UINT16 nSizingFlags = GetSizingFlags();
411 if( nSizingFlags & SIZING_TOP )
413 if( _rPos.Y() < 0 )
414 aSizingRect.Top() = 0;
415 else
416 aSizingRect.Top() = _rPos.Y();
419 if( nSizingFlags & SIZING_BOTTOM )
421 if( _rPos.Y() > _rOutputSize.Height() )
422 aSizingRect.Bottom() = _rOutputSize.Height();
423 else
424 aSizingRect.Bottom() = _rPos.Y();
428 if( nSizingFlags & SIZING_RIGHT )
430 if( _rPos.X() > _rOutputSize.Width() )
431 aSizingRect.Right() = _rOutputSize.Width();
432 else
433 aSizingRect.Right() = _rPos.X();
436 if( nSizingFlags & SIZING_LEFT )
438 if( _rPos.X() < 0 )
439 aSizingRect.Left() = 0;
440 else
441 aSizingRect.Left() = _rPos.X();
443 return aSizingRect;
445 // -----------------------------------------------------------------------------
446 void OTableWindow::setSizingFlag(const Point& _rPos)
448 Size aOutSize = GetOutputSizePixel();
449 //////////////////////////////////////////////////////////////////////
450 // Flags anpassen, wenn Mauszeiger in sizingArea
451 m_nSizingFlags = SIZING_NONE;
453 if( _rPos.X() < TABWIN_SIZING_AREA )
454 m_nSizingFlags |= SIZING_LEFT;
456 if( _rPos.Y() < TABWIN_SIZING_AREA )
457 m_nSizingFlags |= SIZING_TOP;
459 if( _rPos.X() > aOutSize.Width()-TABWIN_SIZING_AREA )
460 m_nSizingFlags |= SIZING_RIGHT;
462 if( _rPos.Y() > aOutSize.Height()-TABWIN_SIZING_AREA )
463 m_nSizingFlags |= SIZING_BOTTOM;
465 //------------------------------------------------------------------------------
466 void OTableWindow::MouseMove( const MouseEvent& rEvt )
468 Window::MouseMove(rEvt);
470 OJoinTableView* pCont = getTableView();
471 if (pCont->getDesignView()->getController().isReadOnly())
472 return;
474 Point aPos = rEvt.GetPosPixel();
475 setSizingFlag(aPos);
476 Pointer aPointer;
479 //////////////////////////////////////////////////////////////////////
480 // Mauszeiger anpassen, wenn Mauszeiger in sizingArea
481 switch( m_nSizingFlags )
483 case SIZING_TOP:
484 case SIZING_BOTTOM:
485 aPointer = Pointer( POINTER_SSIZE );
486 break;
488 case SIZING_LEFT:
489 case SIZING_RIGHT:
490 aPointer = Pointer( POINTER_ESIZE );
491 break;
493 case SIZING_LEFT+SIZING_TOP:
494 case SIZING_RIGHT+SIZING_BOTTOM:
495 aPointer = Pointer( POINTER_SESIZE );
496 break;
498 case SIZING_RIGHT+SIZING_TOP:
499 case SIZING_LEFT+SIZING_BOTTOM:
500 aPointer = Pointer( POINTER_NESIZE );
501 break;
504 SetPointer( aPointer );
507 //------------------------------------------------------------------------------
508 void OTableWindow::MouseButtonDown( const MouseEvent& rEvt )
510 //////////////////////////////////////////////////////////////////////
511 // Wenn sizing, dann bekommt Parent die Nachricht,
512 // dass jetzt die Fenstergroesse seines Childs veraendert wird
513 if( m_nSizingFlags )
514 getTableView()->BeginChildSizing( this, GetPointer() );
516 Window::MouseButtonDown( rEvt );
521 //------------------------------------------------------------------------------
522 void OTableWindow::Resize()
524 //////////////////////////////////////////////////////////////////////
525 // Das Fenster darf nicht verschwinden, deshalb min. Groesse setzen
526 Size aOutSize = GetOutputSizePixel();
527 aOutSize = Size(CalcZoom(aOutSize.Width()),CalcZoom(aOutSize.Height()));
529 long nTitleHeight = CalcZoom( GetTextHeight() )+ CalcZoom( 4 );
531 //////////////////////////////////////////////////////////////////////
532 // Titel und ListBox anpassen
533 long n5Pos = CalcZoom(5);
534 long nPositionX = n5Pos;
535 long nPositionY = n5Pos;
537 // position the image which indicates the type
538 m_aTypeImage.SetPosPixel( Point( nPositionX, nPositionY ) );
539 Size aImageSize( m_aTypeImage.GetImage().GetSizePixel() );
540 m_aTypeImage.SetSizePixel( aImageSize );
542 if ( nTitleHeight < aImageSize.Height() )
543 nTitleHeight = aImageSize.Height();
545 nPositionX += aImageSize.Width() + CalcZoom( 2 );
546 m_aTitle.SetPosSizePixel( Point( nPositionX, nPositionY ), Size( aOutSize.Width() - nPositionX - n5Pos, nTitleHeight ) );
548 long nTitleToList = CalcZoom( 3 );
550 m_pListBox->SetPosSizePixel(
551 Point( n5Pos, nPositionY + nTitleHeight + nTitleToList ),
552 Size( aOutSize.Width() - 2 * n5Pos, aOutSize.Height() - ( nPositionY + nTitleHeight + nTitleToList ) - n5Pos )
555 Window::Invalidate();
558 //------------------------------------------------------------------------------
559 void OTableWindow::SetBoldTitle( BOOL bBold )
561 Font aFont = m_aTitle.GetFont();
562 aFont.SetWeight( bBold?WEIGHT_BOLD:WEIGHT_NORMAL );
563 m_aTitle.SetFont( aFont );
564 m_aTitle.Invalidate();
567 //------------------------------------------------------------------------------
568 void OTableWindow::GetFocus()
570 Window::GetFocus();
571 // we have to forward the focus to our listbox to enable keystokes
572 if(m_pListBox)
573 m_pListBox->GrabFocus();
575 // -----------------------------------------------------------------------------
576 void OTableWindow::setActive(sal_Bool _bActive)
578 SetBoldTitle( _bActive );
579 m_bActive = _bActive;
580 if (!_bActive && m_pListBox && m_pListBox->GetSelectionCount() != 0)
581 m_pListBox->SelectAll(FALSE);
584 //------------------------------------------------------------------------------
585 void OTableWindow::Remove()
587 //////////////////////////////////////////////////////////////////
588 // Fenster loeschen
589 OJoinTableView* pTabWinCont = getTableView();
590 pTabWinCont->RemoveTabWin( this );
591 pTabWinCont->Invalidate();
593 //------------------------------------------------------------------------------
594 BOOL OTableWindow::HandleKeyInput( const KeyEvent& rEvt )
596 const KeyCode& rCode = rEvt.GetKeyCode();
597 USHORT nCode = rCode.GetCode();
598 BOOL bShift = rCode.IsShift();
599 BOOL bCtrl = rCode.IsMod1();
601 BOOL bHandle = FALSE;
603 if( !bCtrl && !bShift && (nCode==KEY_DELETE) )
605 Remove();
606 bHandle = TRUE;
608 return bHandle;
611 //------------------------------------------------------------------------------
612 BOOL OTableWindow::ExistsAConn() const
614 return getTableView()->ExistsAConn(this);
616 //------------------------------------------------------------------------------
617 void OTableWindow::EnumValidFields(::std::vector< ::rtl::OUString>& arrstrFields)
619 arrstrFields.clear();
620 // diese Default-Implementierung zaehlt einfach alles auf, was es in der ListBox gibt ... fuer anderes Verhalten ueberschreiben
621 if ( m_pListBox )
623 arrstrFields.reserve(m_pListBox->GetEntryCount());
624 SvLBoxEntry* pEntryLoop = m_pListBox->First();
625 while (pEntryLoop)
627 arrstrFields.push_back(m_pListBox->GetEntryText(pEntryLoop));
628 pEntryLoop = m_pListBox->Next(pEntryLoop);
632 // -----------------------------------------------------------------------------
633 void OTableWindow::StateChanged( StateChangedType nType )
635 Window::StateChanged( nType );
637 if ( nType == STATE_CHANGE_ZOOM )
639 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
641 Font aFont = rStyleSettings.GetGroupFont();
642 if ( IsControlFont() )
643 aFont.Merge( GetControlFont() );
644 SetZoomedPointFont( aFont );
646 m_aTitle.SetZoom(GetZoom());
647 m_pListBox->SetZoom(GetZoom());
648 Resize();
649 Invalidate();
652 // -----------------------------------------------------------------------------
653 Reference< XAccessible > OTableWindow::CreateAccessible()
655 OTableWindowAccess* pAccessible = new OTableWindowAccess(this);
656 m_pAccessible = pAccessible;
657 return pAccessible;
659 // -----------------------------------------------------------------------------
660 void OTableWindow::Command(const CommandEvent& rEvt)
662 switch (rEvt.GetCommand())
664 case COMMAND_CONTEXTMENU:
666 OJoinController& rController = getDesignView()->getController();
667 if(!rController.isReadOnly() && rController.isConnected())
669 Point ptWhere;
670 if ( rEvt.IsMouseEvent() )
671 ptWhere = rEvt.GetMousePosPixel();
672 else
674 SvLBoxEntry* pCurrent = m_pListBox->GetCurEntry();
675 if ( pCurrent )
676 ptWhere = m_pListBox->GetEntryPosition(pCurrent);
677 else
678 ptWhere = m_aTitle.GetPosPixel();
681 PopupMenu aContextMenu(ModuleRes(RID_MENU_JOINVIEW_TABLE));
682 switch (aContextMenu.Execute(this, ptWhere))
684 case SID_DELETE:
685 Remove();
686 break;
689 break;
691 default:
692 Window::Command(rEvt);
695 // -----------------------------------------------------------------------------
696 long OTableWindow::PreNotify(NotifyEvent& rNEvt)
698 BOOL bHandled = FALSE;
699 switch (rNEvt.GetType())
701 case EVENT_KEYINPUT:
703 if ( getDesignView()->getController().isReadOnly() )
704 break;
706 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
707 const KeyCode& rCode = pKeyEvent->GetKeyCode();
708 if ( rCode.IsMod1() )
710 Point aStartPoint = GetPosPixel();
711 if ( rCode.IsShift() )
713 aStartPoint.X() = GetSizePixel().Width();
714 aStartPoint.Y() = GetSizePixel().Height();
717 switch( rCode.GetCode() )
719 case KEY_DOWN:
720 bHandled = TRUE;
721 aStartPoint.Y() += m_nMoveIncrement;
722 break;
723 case KEY_UP:
724 bHandled = TRUE;
725 aStartPoint.Y() += -m_nMoveIncrement;
726 break;
727 case KEY_LEFT:
728 bHandled = TRUE;
729 aStartPoint.X() += -m_nMoveIncrement;
730 break;
731 case KEY_RIGHT:
732 bHandled = TRUE;
733 aStartPoint.X() += m_nMoveIncrement;
734 break;
736 if ( bHandled )
738 if ( rCode.IsShift() )
740 OJoinTableView* pView = getTableView();
741 Point ptOld = GetPosPixel();
742 Size aSize = pView->getRealOutputSize();
743 Size aNewSize(aStartPoint.X(),aStartPoint.Y());
744 if ( ((ptOld.X() + aNewSize.Width()) <= aSize.Width())
745 && ((ptOld.Y() + aNewSize.Height()) <= aSize.Height()) )
747 if ( aNewSize.Width() < TABWIN_WIDTH_MIN )
748 aNewSize.Width() = TABWIN_WIDTH_MIN;
749 if ( aNewSize.Height() < TABWIN_HEIGHT_MIN )
750 aNewSize.Height() = TABWIN_HEIGHT_MIN;
752 Size szOld = GetSizePixel();
754 aNewSize = Size(pView->CalcZoom(aNewSize.Width()),pView->CalcZoom(aNewSize.Height()));
755 SetPosSizePixel( ptOld, aNewSize );
756 pView->TabWinSized(this, ptOld, szOld);
757 Invalidate( INVALIDATE_NOCHILDREN );
760 else
762 // remember how often the user moved our window
763 ++m_nMoveCount;
764 if( m_nMoveCount == 5 )
765 m_nMoveIncrement = 10;
766 else if( m_nMoveCount > 15 )
767 m_nMoveCount = m_nMoveIncrement = 20;
769 Point aOldDataPoint = GetData()->GetPosition();
770 Point aNewDataPoint = aStartPoint + getTableView()->GetScrollOffset();
771 if ( aNewDataPoint.X() > -1 && aNewDataPoint.Y() > -1 )
773 OJoinTableView* pView = getTableView();
774 if ( pView->isMovementAllowed(aNewDataPoint, GetData()->GetSize()) )
776 SetPosPixel(aStartPoint);
778 // aNewDataPoint can not be used here because SetPosPixel reset it
779 pView->EnsureVisible(GetData()->GetPosition(), GetData()->GetSize());
780 pView->TabWinMoved(this,aOldDataPoint);
781 Invalidate(INVALIDATE_NOCHILDREN);
782 getDesignView()->getController().setModified( sal_True );
784 else
786 m_nMoveCount = 0; // reset our movement count
787 m_nMoveIncrement = 1;
790 else
792 m_nMoveCount = 0; // reset our movement count
793 m_nMoveIncrement = 1;
796 resetSizingFlag();
798 else
800 m_nMoveCount = 0; // reset our movement count
801 m_nMoveIncrement = 1;
804 else
806 m_nMoveCount = 0; // reset our movement count
807 m_nMoveIncrement = 1;
810 break;
811 case EVENT_KEYUP:
813 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
814 const KeyCode& rCode = pKeyEvent->GetKeyCode();
815 USHORT nKeyCode = rCode.GetCode();
816 if ( rCode.IsMod2() && nKeyCode != KEY_UP && nKeyCode != KEY_DOWN && nKeyCode != KEY_LEFT && nKeyCode != KEY_RIGHT )
818 m_nMoveCount = 0; // reset our movement count
819 m_nMoveIncrement = 1;
822 break;
824 if (!bHandled)
825 return Window::PreNotify(rNEvt);
826 return 1L;
828 // -----------------------------------------------------------------------------
829 String OTableWindow::getTitle() const
831 return m_aTitle.GetText();
833 // -----------------------------------------------------------------------------
834 void OTableWindow::_elementInserted( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
836 FillListBox();
838 // -----------------------------------------------------------------------------
839 void OTableWindow::_elementRemoved( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
841 FillListBox();
843 // -----------------------------------------------------------------------------
844 void OTableWindow::_elementReplaced( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
846 FillListBox();
848 // -----------------------------------------------------------------------------