1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_JOINTABLEVIEW_HXX
20 #define INCLUDED_DBACCESS_SOURCE_UI_INC_JOINTABLEVIEW_HXX
22 #include <vcl/window.hxx>
23 #include <vcl/timer.hxx>
24 #include <vcl/idle.hxx>
25 #include <vcl/scrbar.hxx>
26 #include <vcl/vclptr.hxx>
27 #include <svtools/transfer.hxx>
29 #include "callbacks.hxx"
30 #include "TableConnectionData.hxx"
31 #include "TableWindowData.hxx"
36 struct AcceptDropEvent
;
37 struct ExecuteDropEvent
;
42 class OTableConnection
;
44 struct OJoinExchangeData
;
45 class OJoinDesignView
;
46 class OTableWindowData
;
47 class OJoinDesignViewAccess
;
49 // this class conatins only the scrollbars to avoid that
50 // the tablewindows clip the scrollbars
52 class OScrollWindowHelper
: public vcl::Window
54 VclPtr
<ScrollBar
> m_aHScrollBar
;
55 VclPtr
<ScrollBar
> m_aVScrollBar
;
56 VclPtr
<vcl::Window
> m_pCornerWindow
;
57 VclPtr
<OJoinTableView
> m_pTableView
;
60 virtual void Resize() override
;
63 OScrollWindowHelper( vcl::Window
* pParent
);
64 virtual ~OScrollWindowHelper();
65 virtual void dispose() override
;
67 void setTableView(OJoinTableView
* _pTableView
);
69 void resetRange(const Point
& _aSize
);
72 ScrollBar
& GetHScrollBar() { return *m_aHScrollBar
.get(); }
73 ScrollBar
& GetVScrollBar() { return *m_aVScrollBar
.get(); }
77 class OJoinTableView
: public vcl::Window
,
78 public IDragTransferableListener
,
79 public DropTargetHelper
81 friend class OJoinMoveTabWinUndoAct
;
84 typedef std::map
<OUString
, VclPtr
<OTableWindow
> > OTableWindowMap
;
87 OTableWindowMap m_aTableMap
;
88 ::std::vector
<VclPtr
<OTableConnection
> > m_vTableConnection
;
90 Idle m_aDragScrollIdle
;
91 Rectangle m_aDragRect
;
92 Rectangle m_aSizingRect
;
94 Point m_aScrollOffset
;
95 Point m_ptPrevDraggingPos
;
99 VclPtr
<OTableWindow
> m_pDragWin
;
100 VclPtr
<OTableWindow
> m_pSizingWin
;
101 VclPtr
<OTableConnection
> m_pSelectedConn
;
104 bool m_bTrackingInitiallyMoved
;
106 DECL_LINK_TYPED(OnDragScrollTimer
, Idle
*, void);
109 VclPtr
<OTableWindow
> m_pLastFocusTabWin
;
110 VclPtr
<OJoinDesignView
> m_pView
;
111 OJoinDesignViewAccess
* m_pAccessible
;
114 OJoinTableView( vcl::Window
* pParent
, OJoinDesignView
* pView
);
115 virtual ~OJoinTableView();
116 virtual void dispose() override
;
119 virtual void StateChanged( StateChangedType nStateChange
) override
;
120 virtual void GetFocus() override
;
121 virtual void LoseFocus() override
;
122 virtual void KeyInput( const KeyEvent
& rEvt
) override
;
124 virtual css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessible() override
;
127 ScrollBar
& GetHScrollBar() { return static_cast<OScrollWindowHelper
*>(GetParent())->GetHScrollBar(); }
128 ScrollBar
& GetVScrollBar() { return static_cast<OScrollWindowHelper
*>(GetParent())->GetVScrollBar(); }
129 DECL_LINK_TYPED( ScrollHdl
, ScrollBar
*, void );
131 void DrawConnections(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
);
132 void InvalidateConnections();
134 void BeginChildMove( OTableWindow
* pTabWin
, const Point
& rMousePos
);
135 void BeginChildSizing( OTableWindow
* pTabWin
, const Pointer
& rPointer
);
137 void NotifyTitleClicked( OTableWindow
* pTabWin
, const Point
& rMousePos
);
139 virtual void AddTabWin(const OUString
& _rComposedName
, const OUString
& rWinName
, bool bNewTable
= false);
140 virtual void RemoveTabWin( OTableWindow
* pTabWin
);
142 // hide all TabWins (does NOT delete them; they are put in an UNDO action)
145 virtual void AddConnection(const OJoinExchangeData
& jxdSource
, const OJoinExchangeData
& jxdDest
) = 0;
147 /** RemoveConnection allows to remove connections from join table view
149 it implies that the same as addConnection
151 @param rConnection the connection which should be removed
152 @param bDelete when true then the connection will be deleted
154 @return an iterator to next valid connection, so it can be used in any loop
156 virtual bool RemoveConnection(VclPtr
<OTableConnection
>& rConnection
, bool bDelete
);
158 /** allows to add new connections to join table view
160 it implies an invalidation of the features ID_BROWSER_ADDTABLE and
161 SID_RELATION_ADD_RELATION also the modified flag will be set to true
163 @param _pConnection the connection which should be added
164 @param _bAddData when true then the data should also be appended
166 void addConnection(OTableConnection
* _pConnection
,bool _bAddData
= true);
168 bool ScrollPane( long nDelta
, bool bHoriz
, bool bPaintScrollBars
);
169 sal_uLong
GetTabWinCount();
170 const Point
& GetScrollOffset() const { return m_aScrollOffset
; }
172 OJoinDesignView
* getDesignView() const { return m_pView
; }
173 OTableWindow
* GetTabWindow( const OUString
& rName
);
175 VclPtr
<OTableConnection
>& GetSelectedConn() { return m_pSelectedConn
; }
176 /** @note NULL is explicitly allowed (then no-op) */
177 void DeselectConn(OTableConnection
* pConn
);
178 void SelectConn(OTableConnection
* pConn
);
180 OTableWindowMap
& GetTabWinMap() { return m_aTableMap
; }
182 /** gives a read only access to the connection vector
184 const ::std::vector
<VclPtr
<OTableConnection
> >& getTableConnections() const { return m_vTableConnection
; }
186 bool ExistsAConn(const OTableWindow
* pFromWin
) const;
188 /** search for all connections of a table
190 @param _pFromWin the table for which connections should be found
191 @return an iterator which can be used to travel all connections of the table
193 ::std::vector
<VclPtr
<OTableConnection
> >::const_iterator
getTableConnections(const OTableWindow
* _pFromWin
) const;
195 /** how many connection belongs to single table
197 @param _pFromWin the table for which connections should be found
198 @return the count of connections which belongs to this table
200 sal_Int32
getConnectionCount(const OTableWindow
* _pFromWin
) const;
202 OTableConnection
* GetTabConn(const OTableWindow
* pLhs
,const OTableWindow
* pRhs
,bool _bSupressCrossOrNaturalJoin
= false,const OTableConnection
* _rpFirstAfter
= nullptr) const;
204 /** clear the window map and connection vector without destroying it
206 that means that the data of the windows and connection will be
209 void clearLayoutInformation();
211 /** set the focus to that tab win which most recently had it
212 (or to the first available one) **/
213 void GrabTabWinFocus();
215 /** take all WinData and ConnData from the document and create the
216 corresponding Wins and Conns */
217 virtual void ReSync() { }
221 That means that all Conns and Wins are deleted from their respective
222 lists and the corresponding Datas removed from the document */
223 virtual void ClearAll();
225 /** @note used by AddTabDlg to see if more tables can be added */
226 virtual bool IsAddAllowed();
227 virtual bool PreNotify(NotifyEvent
& rNEvt
) override
;
230 virtual sal_Int8
AcceptDrop( const AcceptDropEvent
& rEvt
) override
;
231 virtual sal_Int8
ExecuteDrop( const ExecuteDropEvent
& rEvt
) override
;
233 /** @note can be used for special ui handling after d&d */
234 virtual void lookForUiActivities();
236 /** Hook that is called after moving/resizing TabWins
238 The position is 'virtual': the container has a virtual area of
239 which only a part - changeable by scroll bar - is visible.
240 Therefore: ptOldPosition is always positive, even if it represents
241 a point with a negative physical ordinate above the visible area
243 @note The standard implementation just passes the new data to the
246 void TabWinMoved(OTableWindow
* ptWhich
, const Point
& ptOldPosition
);
248 void TabWinSized(OTableWindow
* ptWhich
, const Point
& ptOldPosition
, const Size
& szOldSize
);
252 /** check if the given window is visible.
254 @param _rPoint The Point to check
255 @param _rSize The Size to be check as well
256 @return true if the area is visible, false otherwise
258 bool isMovementAllowed(const Point
& _rPoint
,const Size
& _rSize
);
260 const Size
& getRealOutputSize() const { return m_aOutputSize
; }
262 virtual void EnsureVisible(const OTableWindow
* _pWin
);
263 void EnsureVisible(const Point
& _rPoint
,const Size
& _rSize
);
265 TTableWindowData::value_type
createTableWindowData(const OUString
& _rComposedName
266 ,const OUString
& _sTableName
267 ,const OUString
& _rWinName
);
270 virtual void MouseButtonUp( const MouseEvent
& rEvt
) override
;
271 virtual void MouseButtonDown( const MouseEvent
& rEvt
) override
;
272 virtual void Tracking( const TrackingEvent
& rTEvt
) override
;
273 virtual void Paint( vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
) override
;
274 virtual void ConnDoubleClicked(VclPtr
<OTableConnection
>& rConnection
);
275 void SetDefaultTabWinPosSize( OTableWindow
* pTabWin
);
276 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) override
;
278 virtual void Resize() override
;
280 virtual void dragFinished( ) override
;
281 /// @note here the physical position (that can be changed while
282 /// resizing) is used, as no scrolling can take place while resizing
283 virtual void Command(const CommandEvent
& rEvt
) override
;
285 virtual OTableWindowData
* CreateImpl(const OUString
& _rComposedName
286 ,const OUString
& _sTableName
287 ,const OUString
& _rWinName
);
289 /** factory method to create table windows
291 @param _pData The data corresponding to the window.
292 @return The new TableWindow
294 virtual VclPtr
<OTableWindow
> createWindow(const TTableWindowData::value_type
& _pData
) = 0;
296 /** determines whether the classes Init method should accept a query
297 name, or only table names */
298 virtual bool allowQueries() const;
300 /** called when init fails at the tablewindowdata because the m_xTable
301 object could not provide columns, but no exception was thrown.
302 Expected to throw. */
303 virtual void onNoColumns_throw();
305 virtual bool supressCrossNaturalJoin(const TTableConnectionData::value_type
& _pData
) const;
309 void ScrollWhileDragging();
311 /** opens the context menu to delete a connection
312 @param _aPos the position where the popup menu should appear
313 @param _pSelConnection the connection which should be deleted
315 void executePopup(const Point
& _aPos
, VclPtr
<OTableConnection
>& rSelConnection
);
317 /** invalidates this window without children and set the controller
319 @param _pAction a possible undo action to add at the controller
321 void invalidateAndModify(SfxUndoAction
*_pAction
=nullptr);
324 using Window::Scroll
;
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */