android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / tabledesign / TableDesignControl.cxx
blob18e24c3d5e1233d2bae0a26587a9f7c5269a0985
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 <TableDesignControl.hxx>
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>
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
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)
47 SetHelpId(HID_TABDESIGN_BACKGROUND);
48 SetSizePixel(LogicToPixel(Size(40, 12), MapMode(MapUnit::MapAppFont)));
51 void OTableRowView::Init()
53 EditBrowseBox::Init();
55 vcl::Font aFont( GetDataWindow().GetFont() );
56 aFont.SetWeight( WEIGHT_NORMAL );
57 GetDataWindow().SetFont( aFont );
59 // set font for the headings to light
60 aFont = GetFont();
61 aFont.SetWeight( WEIGHT_LIGHT );
62 SetFont(aFont);
64 // set up HandleColumn for at maximum 5 digits
65 InsertHandleColumn(static_cast<sal_uInt16>(GetTextWidth(OUString('0')) * 4)/*, sal_True */);
67 BrowserMode const nMode = BrowserMode::COLUMNSELECTION | BrowserMode::MULTISELECTION | BrowserMode::KEEPHIGHLIGHT |
68 BrowserMode::HLINES | BrowserMode::VLINES | BrowserMode::AUTOSIZE_LASTCOL;
70 SetMode(nMode);
73 void OTableRowView::KeyInput( const KeyEvent& rEvt )
75 if (IsDeleteAllowed())
77 if (rEvt.GetKeyCode().GetCode() == KEY_DELETE && // Delete rows
78 !rEvt.GetKeyCode().IsShift() &&
79 !rEvt.GetKeyCode().IsMod1())
81 DeleteRows();
82 return;
84 if( rEvt.GetKeyCode().GetCode() == KEY_F2 )
86 css::util::URL aUrl;
87 aUrl.Complete = ".uno:DSBEditDoc";
88 GetView()->getController().dispatch( aUrl,Sequence< PropertyValue >() );
91 EditBrowseBox::KeyInput(rEvt);
94 void OTableRowView::Command(const CommandEvent& rEvt)
97 switch (rEvt.GetCommand())
99 case CommandEventId::ContextMenu:
101 if (!rEvt.IsMouseEvent())
103 EditBrowseBox::Command(rEvt);
104 return;
107 sal_uInt16 nColId = GetColumnId(GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X()));
108 sal_Int32 nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
110 if ( nColId == HANDLE_ID )
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")
126 InsertNewRows( nRow );
127 SetNoSelection();
128 GoToRow( nRow );
129 SeekRow( nRow );
132 return;
135 [[fallthrough]];
137 default:
138 EditBrowseBox::Command(rEvt);
143 void OTableRowView::cut()
145 CopyRows();
146 DeleteRows();
149 void OTableRowView::copy()
151 CopyRows();
154 void OTableRowView::paste()
156 OSL_FAIL("OTableRowView::Paste : (pseudo-) abstract method called !");
159 void OTableRowView::Paste( sal_Int32 nRow )
161 InsertRows( nRow );
164 EditBrowseBox::RowStatus OTableRowView::GetRowStatus(sal_Int32 nRow) const
166 if (nRow >= 0 && m_nDataPos == nRow)
167 return CURRENT;
168 else
169 return CLEAN;
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */