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