LibreOffice Module dbaccess (master) 1
TableDesignControl.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 <TableDesignView.hxx>
22#include <TableController.hxx>
23#include <com/sun/star/util/URL.hpp>
24#include <com/sun/star/beans/PropertyValue.hpp>
25#include <vcl/commandevent.hxx>
26#include <vcl/svapp.hxx>
27#include <vcl/weldutils.hxx>
28#include <helpids.h>
29
30using namespace ::dbaui;
31using namespace ::svt;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::beans;
34using namespace ::com::sun::star::util;
35// Defines
36#define HANDLE_ID 0
37
38OTableRowView::OTableRowView(vcl::Window* pParent)
43 , m_nDataPos(-1)
44 , m_nCurrentPos(-1)
45 , m_nCurUndoActId(0)
46{
48 SetSizePixel(LogicToPixel(Size(40, 12), MapMode(MapUnit::MapAppFont)));
49}
50
52{
54
55 vcl::Font aFont( GetDataWindow().GetFont() );
56 aFont.SetWeight( WEIGHT_NORMAL );
57 GetDataWindow().SetFont( aFont );
58
59 // set font for the headings to light
60 aFont = GetFont();
61 aFont.SetWeight( WEIGHT_LIGHT );
62 SetFont(aFont);
63
64 // set up HandleColumn for at maximum 5 digits
65 InsertHandleColumn(static_cast<sal_uInt16>(GetTextWidth(OUString('0')) * 4)/*, sal_True */);
66
67 BrowserMode const nMode = BrowserMode::COLUMNSELECTION | BrowserMode::MULTISELECTION | BrowserMode::KEEPHIGHLIGHT |
68 BrowserMode::HLINES | BrowserMode::VLINES | BrowserMode::AUTOSIZE_LASTCOL;
69
70 SetMode(nMode);
71}
72
74{
75 if (IsDeleteAllowed())
76 {
77 if (rEvt.GetKeyCode().GetCode() == KEY_DELETE && // Delete rows
78 !rEvt.GetKeyCode().IsShift() &&
79 !rEvt.GetKeyCode().IsMod1())
80 {
81 DeleteRows();
82 return;
83 }
84 if( rEvt.GetKeyCode().GetCode() == KEY_F2 )
85 {
86 css::util::URL aUrl;
87 aUrl.Complete = ".uno:DSBEditDoc";
88 GetView()->getController().dispatch( aUrl,Sequence< PropertyValue >() );
89 }
90 }
92}
93
95{
96
97 switch (rEvt.GetCommand())
98 {
99 case CommandEventId::ContextMenu:
100 {
101 if (!rEvt.IsMouseEvent())
102 {
104 return;
105 }
106
107 sal_uInt16 nColId = GetColumnId(GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X()));
108 sal_Int32 nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
109
110 if ( nColId == HANDLE_ID )
111 {
112 ::tools::Rectangle aRect(rEvt.GetMousePosPixel(), Size(1, 1));
113 weld::Window* pPopupParent = weld::GetPopupParent(*this, aRect);
114 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "dbaccess/ui/tabledesignrowmenu.ui"));
115 std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu("menu"));
116 sal_Int32 nSelectRowCount = GetSelectRowCount();
117 xContextMenu->set_sensitive("cut", nSelectRowCount != 0);
118 xContextMenu->set_sensitive("copy", nSelectRowCount != 0);
119 OUString sIdent = xContextMenu->popup_at_rect(pPopupParent, aRect);
120 if (sIdent == "cut")
121 cut();
122 else if (sIdent == "copy")
123 copy();
124 else if (sIdent == "insert")
125 {
126 InsertNewRows( nRow );
128 GoToRow( nRow );
129 SeekRow( nRow );
130 }
131
132 return;
133 }
134
135 [[fallthrough]];
136 }
137 default:
139 }
140
141}
142
144{
145 CopyRows();
146 DeleteRows();
147}
148
150{
151 CopyRows();
152}
153
155{
156 OSL_FAIL("OTableRowView::Paste : (pseudo-) abstract method called !");
157}
158
159void OTableRowView::Paste( sal_Int32 nRow )
160{
161 InsertRows( nRow );
162}
163
165{
166 if (nRow >= 0 && m_nDataPos == nRow)
167 return CURRENT;
168 else
169 return CLEAN;
170}
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define HANDLE_ID
BrowserMode
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
sal_uInt16 GetColumnId(sal_uInt16 nPos) const
virtual void Command(const CommandEvent &rEvt) override
BrowserDataWin & GetDataWindow() const
bool GoToRow(sal_Int32 nRow)
sal_Int32 GetRowAtYPosPixel(tools::Long nY, bool bRelToBrowser=true) const
void InsertHandleColumn(sal_uLong nWidth)
void SetFont(const vcl::Font &rNewFont)
void SetMode(BrowserMode nMode)
sal_Int32 GetSelectRowCount() const
const vcl::Font & GetFont() const
sal_uInt16 GetColumnAtXPosPixel(tools::Long nX) const
virtual void SetNoSelection() override
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
bool IsMouseEvent() const
const vcl::KeyCode & GetKeyCode() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
OTableController & getController() const
void Paste(sal_Int32 nRow)
virtual void cut() override
virtual bool IsDeleteAllowed()=0
virtual void CopyRows()=0
tools::Long m_nDataPos
currently needed row
virtual OTableDesignView * GetView() const =0
virtual void copy() override
virtual void InsertNewRows(sal_Int32 nRow)=0
virtual void Command(const CommandEvent &rEvt) override
virtual void paste() override
virtual void KeyInput(const KeyEvent &rEvt) override
virtual RowStatus GetRowStatus(sal_Int32 nRow) const override
virtual void DeleteRows()=0
virtual void Init() override
virtual void InsertRows(sal_Int32 nRow)=0
virtual void KeyInput(const KeyEvent &rEvt) override
virtual void Init()
virtual bool SeekRow(sal_Int32 nRow) override
void SetWeight(FontWeight)
bool IsMod1() const
sal_uInt16 GetCode() const
bool IsShift() const
virtual void SetHelpId(const OUString &) override
EditBrowseBoxFlags
WEIGHT_NORMAL
WEIGHT_LIGHT
constexpr OUStringLiteral HID_TABDESIGN_BACKGROUND
Definition: helpids.h:45
constexpr sal_uInt16 KEY_F2
constexpr sal_uInt16 KEY_DELETE
NONE
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
sal_Int32 m_nCurrentPos
WinBits const WB_3DLOOK
WinBits const WB_TABSTOP
WinBits const WB_HIDE