tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / dbaccess / source / ui / querydesign / TableWindowTitle.cxx
blob2990a010298bc0c08eacd9ce6a2076cd1275cc6f
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 .
20 #include <TableWindowTitle.hxx>
21 #include <TableWindow.hxx>
22 #include <vcl/commandevent.hxx>
23 #include <vcl/event.hxx>
24 #include <TableWindowListBox.hxx>
25 #include <TableConnection.hxx>
26 #include <JoinController.hxx>
28 using namespace dbaui;
29 OTableWindowTitle::OTableWindowTitle(OTableWindow* pParent)
30 : InterimItemWindow(pParent, u"dbaccess/ui/tabletitle.ui"_ustr, u"TableTitle"_ustr)
31 , m_pTabWin( pParent )
32 , m_xLabel(m_xBuilder->weld_label(u"label"_ustr))
33 , m_xImage(m_xBuilder->weld_image(u"image"_ustr))
35 m_xLabel->connect_mouse_press(LINK(this, OTableWindowTitle, MousePressHdl));
38 OTableWindowTitle::~OTableWindowTitle()
40 disposeOnce();
43 void OTableWindowTitle::dispose()
45 m_xImage.reset();
46 m_xLabel.reset();
47 m_pTabWin.clear();
48 InterimItemWindow::dispose();
51 IMPL_LINK(OTableWindowTitle, MousePressHdl, const MouseEvent&, rEvt, bool)
53 if (rEvt.IsLeft())
55 if( rEvt.GetClicks() == 2)
57 Size aSize(GetTextWidth(GetText()) + 20,
58 m_pTabWin->GetSizePixel().Height() - m_pTabWin->GetListBox()->GetSizePixel().Height());
60 weld::TreeView& rTreeView = m_pTabWin->GetListBox()->get_widget();
61 aSize.AdjustHeight(rTreeView.get_height_rows(rTreeView.n_children() + 2));
62 if (m_pTabWin->GetSizePixel() != aSize)
64 m_pTabWin->SetSizePixel(aSize);
66 OJoinTableView* pView = m_pTabWin->getTableView();
67 assert(pView && "No OJoinTableView!");
68 for (auto& conn : pView->getTableConnections())
69 conn->RecalcLines();
71 pView->InvalidateConnections();
72 pView->getDesignView()->getController().setModified(true);
73 pView->Invalidate(InvalidateFlags::NoChildren);
76 else
78 Point aPos = rEvt.GetPosPixel();
79 aPos = OutputToScreenPixel( aPos );
80 OJoinTableView* pView = m_pTabWin->getTableView();
81 OSL_ENSURE(pView,"No OJoinTableView!");
82 pView->NotifyTitleClicked( static_cast<OTableWindow*>(GetParent()), aPos );
85 else if (rEvt.IsRight())
87 CommandEvent aCEvt(rEvt.GetPosPixel(), CommandEventId::ContextMenu, true);
88 // tdf#94709 - protect shutdown code-path.
89 VclPtr<OTableWindow> xTabWin(m_pTabWin);
90 xTabWin->Command(aCEvt);
92 return false;
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */