1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef DBAUI_JOINTABLEVIEW_HXX 28 #define DBAUI_JOINTABLEVIEW_HXX 29 30 #ifndef _SV_WINDOW_HXX 31 #include <vcl/window.hxx> 32 #endif 33 #ifndef _SV_TIMER_HXX 34 #include <vcl/timer.hxx> 35 #endif 36 #ifndef _SV_SCRBAR_HXX 37 #include <vcl/scrbar.hxx> 38 #endif 39 #ifndef _RTTI_HXX 40 #include <tools/rtti.hxx> 41 #endif 42 #ifndef _TRANSFER_HXX 43 #include <svtools/transfer.hxx> 44 #endif 45 46 #ifndef _COMPHELPER_STLTYPES_HXX_ 47 #include <comphelper/stl_types.hxx> 48 #endif 49 #ifndef _DBACCESS_UI_CALLBACKS_HXX_ 50 #include "callbacks.hxx" 51 #endif 52 #include "TableConnectionData.hxx" 53 #include "TableWindowData.hxx" 54 #include <memory> 55 #include <vector> 56 57 struct AcceptDropEvent; 58 struct ExecuteDropEvent; 59 class SfxUndoAction; 60 namespace dbaui 61 { 62 class OTableConnection; 63 class OTableWindow; 64 struct OJoinExchangeData; 65 class OJoinDesignView; 66 class OTableWindowData; 67 class OJoinDesignViewAccess; 68 69 // this class conatins only the scrollbars to avoid that the tablewindows clip the scrollbars 70 class OJoinTableView; 71 class OScrollWindowHelper : public Window 72 { 73 ScrollBar m_aHScrollBar; 74 ScrollBar m_aVScrollBar; 75 Window* m_pCornerWindow; 76 OJoinTableView* m_pTableView; 77 78 protected: 79 virtual void Resize(); 80 public: 81 OScrollWindowHelper( Window* pParent); 82 ~OScrollWindowHelper(); 83 84 void setTableView(OJoinTableView* _pTableView); 85 86 void resetRange(const Point& _aSize); 87 88 // own methods 89 ScrollBar* GetHScrollBar() { return &m_aHScrollBar; } 90 ScrollBar* GetVScrollBar() { return &m_aVScrollBar; } 91 }; 92 93 94 class OJoinTableView : public Window 95 ,public IDragTransferableListener 96 ,public DropTargetHelper 97 { 98 friend class OJoinMoveTabWinUndoAct; 99 public: 100 DECLARE_STL_USTRINGACCESS_MAP(OTableWindow*,OTableWindowMap); 101 private: 102 OTableWindowMap m_aTableMap; 103 ::std::vector<OTableConnection*> m_vTableConnection; 104 105 Timer m_aDragScrollTimer; 106 Rectangle m_aDragRect; 107 Rectangle m_aSizingRect; 108 Point m_aDragOffset; 109 Point m_aScrollOffset; 110 Point m_ptPrevDraggingPos; 111 Size m_aOutputSize; 112 113 114 OTableWindow* m_pDragWin; 115 OTableWindow* m_pSizingWin; 116 OTableConnection* m_pSelectedConn; 117 118 119 sal_Bool m_bTrackingInitiallyMoved; 120 121 DECL_LINK(OnDragScrollTimer, void*); 122 123 protected: 124 OTableWindow* m_pLastFocusTabWin; 125 OJoinDesignView* m_pView; 126 OJoinDesignViewAccess* m_pAccessible; 127 128 public: 129 OJoinTableView( Window* pParent, OJoinDesignView* pView ); 130 virtual ~OJoinTableView(); 131 132 // window override 133 virtual void StateChanged( StateChangedType nStateChange ); 134 virtual void GetFocus(); 135 virtual void LoseFocus(); 136 virtual void KeyInput( const KeyEvent& rEvt ); 137 // Accessibility 138 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible(); 139 140 // own methods 141 ScrollBar* GetHScrollBar() { return static_cast<OScrollWindowHelper*>(GetParent())->GetHScrollBar(); } 142 ScrollBar* GetVScrollBar() { return static_cast<OScrollWindowHelper*>(GetParent())->GetVScrollBar(); } 143 DECL_LINK( ScrollHdl, ScrollBar* ); 144 145 void DrawConnections( const Rectangle& rRect ); 146 void InvalidateConnections(); 147 148 void BeginChildMove( OTableWindow* pTabWin, const Point& rMousePos ); 149 void BeginChildSizing( OTableWindow* pTabWin, const Pointer& rPointer ); 150 151 void NotifyTitleClicked( OTableWindow* pTabWin, const Point rMousePos ); 152 153 virtual void AddTabWin(const ::rtl::OUString& _rComposedName, const ::rtl::OUString& rWinName, sal_Bool bNewTable = sal_False); 154 virtual void RemoveTabWin( OTableWindow* pTabWin ); 155 156 // alle TabWins verstecken (NICHT loeschen, sie werden in eine Undo-Action gepackt) 157 virtual void HideTabWins(); 158 159 virtual void AddConnection(const OJoinExchangeData& jxdSource, const OJoinExchangeData& jxdDest) = 0; 160 161 /** RemoveConnection allows to remove connections from join table view, it implies that the same as addConnection 162 163 @param _pConnection 164 the connection which should be removed 165 @param _bDelete 166 when truie then the connection will be deleted 167 168 @return an iterator to next valid connection, so it can be used in any loop 169 */ 170 virtual bool RemoveConnection(OTableConnection* _pConnection,sal_Bool _bDelete); 171 172 /** allows to add new connections to join table view, it implies an invalidation of the features 173 ID_BROWSER_ADDTABLE and SID_RELATION_ADD_RELATION also the modified flag will be set to true 174 @param _pConnection 175 the connection which should be added 176 @param _bAddData 177 <TRUE/> when the data should also be appended 178 */ 179 void addConnection(OTableConnection* _pConnection,sal_Bool _bAddData = sal_True); 180 181 sal_Bool ScrollPane( long nDelta, sal_Bool bHoriz, sal_Bool bPaintScrollBars ); 182 sal_uLong GetTabWinCount(); 183 Point GetScrollOffset() const { return m_aScrollOffset; } 184 185 OJoinDesignView* getDesignView() const { return m_pView; } 186 OTableWindow* GetTabWindow( const String& rName ); 187 188 OTableConnection* GetSelectedConn() { return m_pSelectedConn; } 189 void DeselectConn(OTableConnection* pConn); // NULL ist ausdruecklich zugelassen, dann passiert nichts 190 void SelectConn(OTableConnection* pConn); 191 192 OTableWindowMap* GetTabWinMap() { return &m_aTableMap; } 193 const OTableWindowMap* GetTabWinMap() const { return &m_aTableMap; } 194 195 /** gives a read only access to the connection vector 196 */ 197 const ::std::vector<OTableConnection*>* getTableConnections() const { return &m_vTableConnection; } 198 199 200 sal_Bool ExistsAConn(const OTableWindow* pFromWin) const; 201 202 /** getTableConnections searchs for all connections of a table 203 @param _pFromWin the table for which connections should be found 204 205 @return an iterator which can be used to travel all connections of the table 206 */ 207 ::std::vector<OTableConnection*>::const_iterator getTableConnections(const OTableWindow* _pFromWin) const; 208 209 /** getConnectionCount returns how many connection belongs to single table 210 @param _pFromWin the table for which connections should be found 211 212 @return the count of connections wich belongs to this table 213 */ 214 sal_Int32 getConnectionCount(const OTableWindow* _pFromWin) const; 215 216 OTableConnection* GetTabConn(const OTableWindow* pLhs,const OTableWindow* pRhs,bool _bSupressCrossOrNaturalJoin = false,const OTableConnection* _rpFirstAfter = NULL) const; 217 218 // clears the window map and connection vector without destroying it 219 // that means teh data of the windows and connection will be untouched 220 void clearLayoutInformation(); 221 222 // set the focus to that tab win which most recently had it (or to the first available one) 223 void GrabTabWinFocus(); 224 225 // ReSync ist dazu gedacht, aus dem Dokument alle WinData und ConnData zu holen und entsprechend Wins und Conns anzulegen 226 virtual void ReSync() { } 227 // ClearAll implementiert ein hartes Loeschen, es werden alle Conns und alle Wins aus ihren jeweiligen Listen geloescht 228 // sowie die entsprechenden Datas aus dem Dokument ausgetragen 229 virtual void ClearAll(); 230 231 // wird vom AddTabDlg benutzt, um festzustellen, ob noch Tabellen hinzugefuegt werden duerfen 232 virtual sal_Bool IsAddAllowed(); 233 virtual long PreNotify(NotifyEvent& rNEvt); 234 235 // DnD stuff 236 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ); 237 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ); 238 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ); 239 240 /** 241 can be used in derevied classes to make some special ui handling 242 after d&d 243 */ 244 virtual void lookForUiActivities(); 245 246 // wird nach Verschieben/Groessenaenderung der TabWins aufgerufen (die Standardimplementation reicht die neuen Daten einfach 247 // an die Daten des Wins weiter) 248 virtual void TabWinMoved(OTableWindow* ptWhich, const Point& ptOldPosition); 249 // die Position ist "virtuell" : der Container hat sozusagen eine virtuelle Flaeche, von der immer nur ein bestimmter Bereich 250 // - der mittels der Scrollbar veraendert werden kann - zu sehen ist. Insbesondere hat ptOldPosition immer positive Koordinaten, 251 // auch wenn er einen Punkt oberhalb des aktuell sichtbaren Bereichs bezeichnet, dessen physische Ordinate eigentlich 252 // negativ ist. 253 virtual void TabWinSized(OTableWindow* ptWhich, const Point& ptOldPosition, const Size& szOldSize); 254 255 void modified(); 256 257 /** returns if teh given window is visible. 258 @param _rPoint 259 The Point to check 260 @param _rSize 261 The Size to be check as well 262 @return 263 <TRUE/> if the area is visible otherwise <FALSE/> 264 265 */ 266 sal_Bool isMovementAllowed(const Point& _rPoint,const Size& _rSize); 267 268 Size getRealOutputSize() const { return m_aOutputSize; } 269 270 271 272 virtual void EnsureVisible(const OTableWindow* _pWin); 273 virtual void EnsureVisible(const Point& _rPoint,const Size& _rSize); 274 275 TTableWindowData::value_type createTableWindowData(const ::rtl::OUString& _rComposedName 276 ,const ::rtl::OUString& _sTableName 277 ,const ::rtl::OUString& _rWinName); 278 279 protected: 280 virtual void MouseButtonUp( const MouseEvent& rEvt ); 281 virtual void MouseButtonDown( const MouseEvent& rEvt ); 282 virtual void Tracking( const TrackingEvent& rTEvt ); 283 virtual void Paint( const Rectangle& rRect ); 284 virtual void ConnDoubleClicked( OTableConnection* pConnection ); 285 virtual void SetDefaultTabWinPosSize( OTableWindow* pTabWin ); 286 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 287 288 virtual void Resize(); 289 290 virtual void dragFinished( ); 291 // hier ist die Position (die sich waehrend des Sizings aendern kann) physisch, da waehrend des Sizens nicht gescrollt wird 292 virtual void Command(const CommandEvent& rEvt); 293 294 virtual OTableWindowData* CreateImpl(const ::rtl::OUString& _rComposedName 295 ,const ::rtl::OUString& _sTableName 296 ,const ::rtl::OUString& _rWinName); 297 298 /** factory method to create table windows 299 @param _pData 300 The data corresponding to the window. 301 @return 302 The new TableWindow 303 */ 304 virtual OTableWindow* createWindow(const TTableWindowData::value_type& _pData) = 0; 305 306 /** determines whether the classes Init method should accept a query name, or only table names 307 */ 308 virtual bool allowQueries() const; 309 310 /** called when init fails at the tablewindowdata because the m_xTable object could not provide columns, but no 311 exception was thrown. Expected to throw. 312 */ 313 virtual void onNoColumns_throw(); 314 315 virtual bool supressCrossNaturalJoin(const TTableConnectionData::value_type& _pData) const; 316 317 private: 318 void InitColors(); 319 sal_Bool ScrollWhileDragging(); 320 321 /** executePopup opens the context menu to delate a connection 322 @param _aPos the position where the popup menu should appear 323 @param _pSelConnection the connection which should be deleted 324 */ 325 void executePopup(const Point& _aPos,OTableConnection* _pSelConnection); 326 327 /** invalidateAndModify invalidates this window without children and 328 set the controller modified 329 @param _pAction a possible undo action to add at the controller 330 */ 331 void invalidateAndModify(SfxUndoAction *_pAction=NULL); 332 333 private: 334 using Window::Scroll; 335 }; 336 } 337 #endif // DBAUI_JOINTABLEVIEW_HXX 338