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
20 #include <TableDesignControl.hxx>
21 #include <TableDesignView.hxx>
22 #include <TableController.hxx>
23 #include <browserids.hxx>
24 #include <com/sun/star/util/URL.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <vcl/builder.hxx>
27 #include <vcl/commandevent.hxx>
28 #include <helpids.h>
29
30 using namespace ::dbaui;
31 using namespace ::svt;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::util;
35 // Defines
36 #define HANDLE_ID 0
37
OTableRowView(vcl::Window * pParent)38 OTableRowView::OTableRowView(vcl::Window* pParent)
39 : EditBrowseBox(pParent, EditBrowseBoxFlags::NONE, WB_TABSTOP|WB_HIDE|WB_3DLOOK,
40 BrowserMode::COLUMNSELECTION | BrowserMode::MULTISELECTION |
41 BrowserMode::AUTOSIZE_LASTCOL | BrowserMode::KEEPHIGHLIGHT |
42 BrowserMode::HLINES | BrowserMode::VLINES)
43 , m_nDataPos(-1)
44 , m_nCurrentPos(-1)
45 , m_nCurUndoActId(0)
46 {
47 SetHelpId(HID_TABDESIGN_BACKGROUND);
48 SetSizePixel(LogicToPixel(Size(40, 12), MapMode(MapUnit::MapAppFont)));
49 }
50
Init()51 void OTableRowView::Init()
52 {
53 EditBrowseBox::Init();
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
KeyInput(const KeyEvent & rEvt)73 void OTableRowView::KeyInput( const KeyEvent& rEvt )
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 }
91 EditBrowseBox::KeyInput(rEvt);
92 }
93
Command(const CommandEvent & rEvt)94 void OTableRowView::Command(const CommandEvent& rEvt)
95 {
96
97 switch (rEvt.GetCommand())
98 {
99 case CommandEventId::ContextMenu:
100 {
101 if (!rEvt.IsMouseEvent())
102 {
103 EditBrowseBox::Command(rEvt);
104 return;
105 }
106
107 sal_uInt16 nColId = GetColumnId(GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X()));
108 long nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
109
110 if ( nColId == HANDLE_ID )
111 {
112 VclBuilder aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "dbaccess/ui/querycolmenu.ui", "");
113 VclPtr<PopupMenu> aContextMenu(aBuilder.get_menu("menu"));
114 long nSelectRowCount = GetSelectRowCount();
115 aContextMenu->EnableItem(aContextMenu->GetItemId("cut"), nSelectRowCount != 0);
116 aContextMenu->EnableItem(aContextMenu->GetItemId("copy"), nSelectRowCount != 0);
117 aContextMenu->EnableItem(aContextMenu->GetItemId("paste"), false);
118 aContextMenu->EnableItem(aContextMenu->GetItemId("delete"), false);
119 aContextMenu->Execute(this, rEvt.GetMousePosPixel());
120 OString sIdent = aContextMenu->GetCurItemIdent();
121 if (sIdent == "cut")
122 cut();
123 else if (sIdent == "copy")
124 copy();
125 else if (sIdent == "paste")
126 {
127 Paste( nRow );
128 SetNoSelection();
129 GoToRow( nRow );
130 SeekRow( nRow );
131 }
132 else if (sIdent == "delete")
133 DeleteRows();
134 else if (sIdent == "insert")
135 {
136 InsertNewRows( nRow );
137 SetNoSelection();
138 GoToRow( nRow );
139 SeekRow( nRow );
140 }
141
142 return;
143 }
144
145 [[fallthrough]];
146 }
147 default:
148 EditBrowseBox::Command(rEvt);
149 }
150
151 }
152
cut()153 void OTableRowView::cut()
154 {
155 CopyRows();
156 DeleteRows();
157 }
158
copy()159 void OTableRowView::copy()
160 {
161 CopyRows();
162 }
163
paste()164 void OTableRowView::paste()
165 {
166 OSL_FAIL("OTableRowView::Paste : (pseudo-) abstract method called !");
167 }
168
Paste(long nRow)169 void OTableRowView::Paste( long nRow )
170 {
171 InsertRows( nRow );
172 }
173
GetRowStatus(long nRow) const174 EditBrowseBox::RowStatus OTableRowView::GetRowStatus(long nRow) const
175 {
176 if (nRow >= 0 && m_nDataPos == nRow)
177 return CURRENT;
178 else
179 return CLEAN;
180 }
181
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
183