Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / inc / JoinTableView.hxx
blob9e2e2bf57e25c3802eef7e3621619d0314dd0b02
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
21 #include <svtools/scrolladaptor.hxx>
22 #include <vcl/window.hxx>
23 #include <vcl/timer.hxx>
24 #include <vcl/idle.hxx>
25 #include <vcl/vclptr.hxx>
26 #include <vcl/transfer.hxx>
28 #include "callbacks.hxx"
29 #include "TableConnectionData.hxx"
30 #include "TableWindowData.hxx"
32 #include <map>
33 #include <vector>
35 struct AcceptDropEvent;
36 struct ExecuteDropEvent;
37 class SfxUndoAction;
39 namespace dbaui
41 class OTableConnection;
42 class OTableWindow;
43 struct OJoinExchangeData;
44 class OJoinDesignView;
45 class OTableWindowData;
46 class OJoinDesignViewAccess;
48 // this class contains only the scrollbars to avoid that
49 // the tablewindows clip the scrollbars
50 class OJoinTableView;
51 class OScrollWindowHelper : public vcl::Window
53 VclPtr<ScrollAdaptor> m_aHScrollBar;
54 VclPtr<ScrollAdaptor> m_aVScrollBar;
55 VclPtr<OJoinTableView> m_pTableView;
57 protected:
58 virtual void Resize() override;
60 public:
61 OScrollWindowHelper( vcl::Window* pParent);
62 virtual ~OScrollWindowHelper() override;
63 virtual void dispose() override;
65 void setTableView(OJoinTableView* _pTableView);
67 void resetRange(const Point& _aSize);
69 // own methods
70 ScrollAdaptor& GetHScrollBar() { return *m_aHScrollBar; }
71 ScrollAdaptor& GetVScrollBar() { return *m_aVScrollBar; }
75 class OJoinTableView : public vcl::Window,
76 public IDragTransferableListener,
77 public DropTargetHelper
79 friend class OJoinMoveTabWinUndoAct;
81 public:
82 typedef std::map<OUString, VclPtr<OTableWindow> > OTableWindowMap;
84 private:
85 OTableWindowMap m_aTableMap;
86 std::vector<VclPtr<OTableConnection> > m_vTableConnection;
88 Idle m_aDragScrollIdle;
89 tools::Rectangle m_aDragRect;
90 tools::Rectangle m_aSizingRect;
91 Point m_aDragOffset;
92 Point m_aScrollOffset;
93 Point m_ptPrevDraggingPos;
94 Size m_aOutputSize;
97 VclPtr<OTableWindow> m_pDragWin;
98 VclPtr<OTableWindow> m_pSizingWin;
99 VclPtr<OTableConnection> m_pSelectedConn;
102 DECL_LINK(OnDragScrollTimer, Timer*, void);
104 protected:
105 VclPtr<OTableWindow> m_pLastFocusTabWin;
106 VclPtr<OJoinDesignView> m_pView;
107 rtl::Reference<OJoinDesignViewAccess> m_pAccessible;
109 public:
110 OJoinTableView( vcl::Window* pParent, OJoinDesignView* pView );
111 virtual ~OJoinTableView() override;
112 virtual void dispose() override;
114 // window override
115 virtual void StateChanged( StateChangedType nStateChange ) override;
116 virtual void GetFocus() override;
117 virtual void LoseFocus() override;
118 virtual void KeyInput( const KeyEvent& rEvt ) override;
119 // Accessibility
120 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
122 // own methods
123 ScrollAdaptor& GetHScrollBar() { return static_cast<OScrollWindowHelper*>(GetParent())->GetHScrollBar(); }
124 ScrollAdaptor& GetVScrollBar() { return static_cast<OScrollWindowHelper*>(GetParent())->GetVScrollBar(); }
125 DECL_LINK(VertScrollHdl, weld::Scrollbar&, void);
126 DECL_LINK(HorzScrollHdl, weld::Scrollbar&, void);
128 void DrawConnections(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect);
129 void InvalidateConnections();
131 void BeginChildMove( OTableWindow* pTabWin, const Point& rMousePos );
132 void BeginChildSizing( OTableWindow* pTabWin, PointerStyle nPointer );
134 void NotifyTitleClicked( OTableWindow* pTabWin, const Point& rMousePos );
136 virtual void AddTabWin(const OUString& _rComposedName, const OUString& rWinName, bool bNewTable = false);
137 virtual void RemoveTabWin( OTableWindow* pTabWin );
139 // hide all TabWins (does NOT delete them; they are put in an UNDO action)
140 void HideTabWins();
142 virtual void AddConnection(const OJoinExchangeData& jxdSource, const OJoinExchangeData& jxdDest) = 0;
144 /** RemoveConnection allows to remove connections from join table view
146 it implies that the same as addConnection
148 @param rConnection the connection which should be removed
149 @param bDelete when true then the connection will be deleted
151 @return an iterator to next valid connection, so it can be used in any loop
153 virtual bool RemoveConnection(VclPtr<OTableConnection>& rConnection, bool bDelete);
155 /** allows to add new connections to join table view
157 it implies an invalidation of the features ID_BROWSER_ADDTABLE and
158 SID_RELATION_ADD_RELATION also the modified flag will be set to true
160 @param _pConnection the connection which should be added
161 @param _bAddData when true then the data should also be appended
163 void addConnection(OTableConnection* _pConnection,bool _bAddData = true);
165 bool ScrollPane( tools::Long nDelta, bool bHoriz, bool bPaintScrollBars );
166 sal_Int64 GetTabWinCount() const;
167 const Point& GetScrollOffset() const { return m_aScrollOffset; }
169 OJoinDesignView* getDesignView() const { return m_pView; }
170 OTableWindow* GetTabWindow( const OUString& rName );
172 VclPtr<OTableConnection>& GetSelectedConn() { return m_pSelectedConn; }
173 /** @note NULL is explicitly allowed (then no-op) */
174 void DeselectConn(OTableConnection* pConn);
175 void SelectConn(OTableConnection* pConn);
177 OTableWindowMap& GetTabWinMap() { return m_aTableMap; }
179 /** gives a read only access to the connection vector
181 const std::vector<VclPtr<OTableConnection> >& getTableConnections() const { return m_vTableConnection; }
183 bool ExistsAConn(const OTableWindow* pFromWin) const;
185 /** search for all connections of a table
187 @param _pFromWin the table for which connections should be found
188 @return an iterator which can be used to travel all connections of the table
190 std::vector<VclPtr<OTableConnection> >::const_iterator getTableConnections(const OTableWindow* _pFromWin) const;
192 /** how many connection belongs to single table
194 @param _pFromWin the table for which connections should be found
195 @return the count of connections which belongs to this table
197 sal_Int32 getConnectionCount(const OTableWindow* _pFromWin) const;
199 OTableConnection* GetTabConn(const OTableWindow* pLhs,const OTableWindow* pRhs,bool _bSuppressCrossOrNaturalJoin = false) const;
201 /** clear the window map and connection vector without destroying it
203 that means that the data of the windows and connection will be
204 untouched
206 void clearLayoutInformation();
208 /** set the focus to that tab win which most recently had it
209 (or to the first available one) **/
210 void GrabTabWinFocus();
212 /** take all WinData and ConnData from the document and create the
213 corresponding Wins and Conns */
214 virtual void ReSync() { }
216 /** Hard deletion
218 That means that all Conns and Wins are deleted from their respective
219 lists and the corresponding Data removed from the document */
220 virtual void ClearAll();
222 /** @note used by AddTabDlg to see if more tables can be added */
223 virtual bool IsAddAllowed();
224 virtual bool PreNotify(NotifyEvent& rNEvt) override;
226 // DnD stuff
227 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override;
228 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override;
230 /** @note can be used for special ui handling after d&d */
231 virtual void lookForUiActivities();
233 /** Hook that is called after moving/resizing TabWins
235 The position is 'virtual': the container has a virtual area of
236 which only a part - changeable by scroll bar - is visible.
237 Therefore: ptOldPosition is always positive, even if it represents
238 a point with a negative physical ordinate above the visible area
240 @note The standard implementation just passes the new data to the
241 Wins
243 void TabWinMoved(OTableWindow* ptWhich, const Point& ptOldPosition);
245 void TabWinSized(OTableWindow* ptWhich, const Point& ptOldPosition, const Size& szOldSize);
247 void modified();
249 /** check if the given window is visible.
251 @param _rPoint The Point to check
252 @param _rSize The Size to be check as well
253 @return true if the area is visible, false otherwise
255 bool isMovementAllowed(const Point& _rPoint,const Size& _rSize);
257 const Size& getRealOutputSize() const { return m_aOutputSize; }
259 virtual void EnsureVisible(const OTableWindow* _pWin);
260 void EnsureVisible(const Point& _rPoint,const Size& _rSize);
262 TTableWindowData::value_type createTableWindowData(const OUString& _rComposedName
263 ,const OUString& _sTableName
264 ,const OUString& _rWinName);
266 protected:
267 virtual void MouseButtonUp( const MouseEvent& rEvt ) override;
268 virtual void MouseButtonDown( const MouseEvent& rEvt ) override;
269 virtual void Tracking( const TrackingEvent& rTEvt ) override;
270 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
271 virtual void ConnDoubleClicked(VclPtr<OTableConnection>& rConnection);
272 void SetDefaultTabWinPosSize( OTableWindow* pTabWin );
273 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
275 virtual void Resize() override;
277 virtual void dragFinished( ) override;
278 /// @note here the physical position (that can be changed while
279 /// resizing) is used, as no scrolling can take place while resizing
280 virtual void Command(const CommandEvent& rEvt) override;
282 virtual std::shared_ptr<OTableWindowData> CreateImpl(const OUString& _rComposedName
283 ,const OUString& _sTableName
284 ,const OUString& _rWinName);
286 /** factory method to create table windows
288 @param _pData The data corresponding to the window.
289 @return The new TableWindow
291 virtual VclPtr<OTableWindow> createWindow(const TTableWindowData::value_type& _pData) = 0;
293 /** determines whether the classes Init method should accept a query
294 name, or only table names */
295 virtual bool allowQueries() const;
297 /** called when init fails at the tablewindowdata because the m_xTable
298 object could not provide columns, but no exception was thrown.
299 Expected to throw. */
300 virtual void onNoColumns_throw();
302 virtual bool suppressCrossNaturalJoin(const TTableConnectionData::value_type& _pData) const;
304 private:
305 void InitColors();
306 void ScrollWhileDragging();
308 /** opens the context menu to delete a connection
309 @param _aPos the position where the popup menu should appear
310 @param _pSelConnection the connection which should be deleted
312 void executePopup(const Point& _aPos, VclPtr<OTableConnection>& rSelConnection);
314 /** invalidates this window without children and set the controller
315 modified
316 @param _pAction a possible undo action to add at the controller
318 void invalidateAndModify(std::unique_ptr<SfxUndoAction> _pAction);
320 private:
321 using Window::Scroll;
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */