LibreOffice Module dbaccess (master) 1
TableWindowListBox.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <TableWindow.hxx>
22#include <JoinController.hxx>
23#include <JoinExchange.hxx>
24#include <JoinTableView.hxx>
25#include <JoinDesignView.hxx>
26#include <osl/diagnose.h>
27#include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
28#include <com/sun/star/sdbc/SQLException.hpp>
29#include <vcl/svapp.hxx>
30#include <vcl/commandevent.hxx>
31#include <o3tl/string_view.hxx>
32
33using namespace dbaui;
34using namespace ::com::sun::star::sdbc;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::datatransfer;
37
38OJoinExchangeData::OJoinExchangeData(OTableWindowListBox* pBox)
39 : pListBox(pBox)
40 , nEntry(pBox->get_widget().get_selected_index())
41{
42}
43
45 : InterimItemWindow(pParent, "dbaccess/ui/tablelistbox.ui", "TableListBox")
46 , m_xTreeView(m_xBuilder->weld_tree_view("treeview"))
47 , m_xDragDropTargetHelper(new TableWindowListBoxHelper(*this, m_xTreeView->get_drop_target()))
48 , m_pTabWin(pParent)
49 , m_nDropEvent(nullptr)
50 , m_nUiEvent(nullptr)
51{
52 m_xTreeView->connect_row_activated(LINK(this, OTableWindowListBox, OnDoubleClick));
53 m_xTreeView->connect_visible_range_changed(LINK(this, OTableWindowListBox, ScrollHdl));
54 m_xTreeView->connect_popup_menu(LINK(this, OTableWindowListBox, CommandHdl));
55
56 m_xHelper.set(new OJoinExchObj);
58 m_xTreeView->enable_drag_source(xHelper, DND_ACTION_LINK);
59 m_xTreeView->connect_drag_begin(LINK(this, OTableWindowListBox, DragBeginHdl));
60}
61
62IMPL_LINK(OTableWindowListBox, CommandHdl, const CommandEvent&, rCEvt, bool)
63{
64 if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
65 return false;
66 m_pTabWin->Command(rCEvt);
67 return true;
68}
69
71{
72 // first show the error msg when existing
73 m_pTabWin->getDesignView()->getController().showError(
74 m_pTabWin->getDesignView()->getController().clearOccurredError());
75 // second look for ui activities which should happen after d&d
76 if (m_nUiEvent)
79 = Application::PostUserEvent(LINK(this, OTableWindowListBox, LookForUiHdl), nullptr, true);
80}
81
83
85{
86 if (m_nDropEvent)
88 if (m_nUiEvent)
90 m_pTabWin.clear();
92 m_xTreeView.reset();
94}
95
96int OTableWindowListBox::GetEntryFromText(std::u16string_view rEntryText)
97{
98 // iterate through the list
99 OJoinDesignView* pView = m_pTabWin->getDesignView();
100 OJoinController& rController = pView->getController();
101
102 try
103 {
104 bool bCase = false;
105 const Reference<XConnection>& xConnection = rController.getConnection();
106 if (xConnection.is())
107 {
108 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
109 if (xMeta.is())
110 bCase = xMeta->supportsMixedCaseQuotedIdentifiers();
111 }
112 for (int nEntry = 0, nCount = m_xTreeView->n_children(); nEntry < nCount; ++nEntry)
113 {
114 if (bCase ? rEntryText == m_xTreeView->get_text(nEntry)
115 : o3tl::equalsIgnoreAsciiCase(rEntryText, m_xTreeView->get_text(nEntry)))
116 return nEntry;
117 }
118 }
119 catch (SQLException&)
120 {
121 }
122
123 return -1;
124}
125
127{
128 // connections of this table, if any, should be redrawn
129 m_pTabWin->getTableView()->Invalidate(InvalidateFlags::NoChildren);
130}
131
132IMPL_LINK(OTableWindowListBox, DragBeginHdl, bool&, rUnsetDragIcon, bool)
133{
134 rUnsetDragIcon = false;
135 if (m_xTreeView->get_selected_index() == -1)
136 {
137 // no drag without a field
138 return true;
139 }
140
141 OJoinTableView* pCont = m_pTabWin->getTableView();
142 if (!pCont->getDesignView()->getController().isReadOnly()
143 && pCont->getDesignView()->getController().isConnected())
144 {
145 // asterisk was not allowed to be copied to selection browsebox
146 bool bFirstNotAllowed = m_xTreeView->is_selected(0) && m_pTabWin->GetData()->IsShowAll();
147 // create a description of the source
148 OJoinExchangeData jxdSource(this);
149 // update the exchange object
150 m_xHelper->setDescriptors(jxdSource, bFirstNotAllowed);
151
152 return false;
153 }
154
155 return true;
156}
157
159{
160 // to enable the autoscroll when we're close to the edges
161 std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
162 bool bHasDestRow = m_xTreeView->get_dest_row_at_pos(_rEvt.maPosPixel, xEntry.get(), true);
163
164 sal_Int8 nDND_Action = DND_ACTION_NONE;
165 // check the format
167 m_xDragDropTargetHelper->GetDataFlavorExVector(),
168 SotClipboardFormatId::SBA_TABID) // this means that the first entry is to be dragged
169 && OJoinExchObj::isFormatAvailable(m_xDragDropTargetHelper->GetDataFlavorExVector()))
170 { // don't drop into the window if it's the drag source itself
171
172 // remove the selection if the dragging operation is leaving the window
173 if (_rEvt.mbLeaving)
174 m_xTreeView->unselect_all();
175 else
176 {
177 if (!bHasDestRow)
178 return DND_ACTION_NONE;
179
180 // automatically select right entry when dragging
181 m_xTreeView->unselect_all();
182 m_xTreeView->select(*xEntry);
183
184 // one cannot drop on the first (*) entry
185 if (!(m_pTabWin->GetData()->IsShowAll()
186 && (m_xTreeView->get_iter_index_in_parent(*xEntry) == 0)))
187 nDND_Action = DND_ACTION_LINK;
188 }
189 }
190 return nDND_Action;
191}
192
193IMPL_LINK_NOARG(OTableWindowListBox, LookForUiHdl, void*, void)
194{
195 m_nUiEvent = nullptr;
196 m_pTabWin->getTableView()->lookForUiActivities();
197}
198
200{
201 // create the connection
202 m_nDropEvent = nullptr;
203 OSL_ENSURE(m_pTabWin, "No TableWindow!");
204 try
205 {
206 OJoinTableView* pCont = m_pTabWin->getTableView();
207 OSL_ENSURE(pCont, "No QueryTableView!");
208 pCont->AddConnection(m_aDropInfo.aSource, m_aDropInfo.aDest);
209 }
210 catch (const SQLException& e)
211 {
212 // remember the exception so that we can show them later when d&d is finished
213 m_pTabWin->getDesignView()->getController().setErrorOccurred(
215 }
216}
217
219{
220 TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
222 { // don't drop into the window if it's the drag source itself
225
226 if (m_nDropEvent)
229 = Application::PostUserEvent(LINK(this, OTableWindowListBox, DropHdl), nullptr, true);
230
231 dragFinished();
232
233 return DND_ACTION_NONE;
234 }
235 return DND_ACTION_NONE;
236}
237
239{
240 if (m_pTabWin)
241 m_pTabWin->setActive(false);
243}
244
246{
247 if (m_pTabWin)
248 m_pTabWin->setActive();
249
250 if (m_xTreeView)
251 {
252 std::unique_ptr<weld::TreeIter> xCurrent = m_xTreeView->make_iterator();
253 if (m_xTreeView->get_cursor(xCurrent.get()))
254 {
255 m_xTreeView->unselect_all();
256 m_xTreeView->select(*xCurrent);
257 }
258 }
259
261}
262
264{
265 // tell my parent
266 vcl::Window* pParent = Window::GetParent();
267 OSL_ENSURE(pParent != nullptr, "OTableWindowListBox::OnDoubleClick : have no Parent !");
268
269 std::unique_ptr<weld::TreeIter> xCurrent = m_xTreeView->make_iterator();
270 if (!m_xTreeView->get_cursor(xCurrent.get()))
271 return false;
272
273 static_cast<OTableWindow*>(pParent)->OnEntryDoubleClicked(*xCurrent);
274
275 return false;
276}
277
279{
280 switch (rEvt.GetCommand())
281 {
282 case CommandEventId::ContextMenu:
283 {
284 static_cast<OTableWindow*>(Window::GetParent())->Command(rEvt);
285 break;
286 }
287 default:
289 }
290}
291
292/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
CommandEventId GetCommand() const
virtual void dispose() override
virtual void GetFocus() override
const DataFlavorExVector & GetDataFlavorExVector() const
OJoinController & getController() const
static bool isFormatAvailable(const DataFlavorExVector &_rFormats, SotClipboardFormatId _nSlotID=SotClipboardFormatId::SBA_JOIN)
static OJoinExchangeData GetSourceDescription(const css::uno::Reference< css::datatransfer::XTransferable > &_rxObject)
OJoinDesignView * getDesignView() const
virtual void AddConnection(const OJoinExchangeData &jxdSource, const OJoinExchangeData &jxdDest)=0
VclPtr< OTableWindow > m_pTabWin
virtual void dragFinished() override
called when a drag operation done with a Transferable has been finished
int GetEntryFromText(std::u16string_view rEntryText)
OTableWindowListBox(OTableWindow *pParent)
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt)
virtual void LoseFocus() override
virtual void dispose() override
std::unique_ptr< TableWindowListBoxHelper > m_xDragDropTargetHelper
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
virtual void GetFocus() override
virtual void Command(const CommandEvent &rEvt) override
std::unique_ptr< weld::TreeView > m_xTreeView
virtual ~OTableWindowListBox() override
rtl::Reference< OJoinExchObj > m_xHelper
vcl::Window * GetParent() const
virtual void Command(const CommandEvent &rCEvt)
virtual void LoseFocus()
int nCount
@ OnDoubleClick
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
const css::datatransfer::dnd::DropTargetDropEvent maDropEvent
OJoinExchangeData aDest
OJoinExchangeData aSource
#define DND_ACTION_LINK
#define DND_ACTION_NONE
signed char sal_Int8