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