bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / tabledesign / TableDesignControl.cxx
blobca2bea139c213060e8889602dcb41f05a9cff97b
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 .
21 #include "TableDesignControl.hxx"
22 #include "dbu_tbl.hrc"
23 #include "TableDesignView.hxx"
24 #include "TableController.hxx"
25 #include "browserids.hxx"
26 #include <com/sun/star/util/URL.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include "dbaccess_helpid.hrc"
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 DBG_NAME(OTableRowView)
39 //------------------------------------------------------------------------
40 OTableRowView::OTableRowView(Window* pParent)
41 :EditBrowseBox(pParent, ModuleRes(RID_DB_TAB_EDITOR),EBBF_NONE,
42 BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_AUTOSIZE_LASTCOL |
43 BROWSER_KEEPSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL)
44 ,m_nDataPos(-1)
45 ,m_nCurrentPos(-1)
46 ,m_nCurUndoActId(0)
47 ,m_bCurrentModified(sal_False)
48 ,m_bUpdatable(sal_False)
49 ,m_bClipboardFilled(sal_False)
51 DBG_CTOR(OTableRowView,NULL);
55 //------------------------------------------------------------------------
56 OTableRowView::~OTableRowView()
59 DBG_DTOR(OTableRowView,NULL);
62 //------------------------------------------------------------------------
63 void OTableRowView::Init()
65 EditBrowseBox::Init();
67 Font aFont( GetDataWindow().GetFont() );
68 aFont.SetWeight( WEIGHT_NORMAL );
69 GetDataWindow().SetFont( aFont );
71 // Font fuer die Ueberschriften auf Light setzen
72 aFont = GetFont();
73 aFont.SetWeight( WEIGHT_LIGHT );
74 SetFont(aFont);
76 // HandleColumn, fuer maximal fuenf Ziffern einrichten
77 InsertHandleColumn(static_cast<sal_uInt16>(GetTextWidth(OUString('0')) * 4)/*, sal_True */);
79 BrowserMode nMode = BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_KEEPSELECTION |
80 BROWSER_HLINESFULL | BROWSER_VLINESFULL | BROWSER_AUTOSIZE_LASTCOL;
81 if (IsUpdatable())
82 nMode |= BROWSER_HIDECURSOR;
84 SetMode(nMode);
87 //------------------------------------------------------------------------
88 void OTableRowView::KeyInput( const KeyEvent& rEvt )
90 if (IsDeleteAllowed(0))
92 if (rEvt.GetKeyCode().GetCode() == KEY_DELETE && // Delete rows
93 !rEvt.GetKeyCode().IsShift() &&
94 !rEvt.GetKeyCode().IsMod1())
96 DeleteRows();
97 return;
99 if( rEvt.GetKeyCode().GetCode() == KEY_F2 )
101 ::com::sun::star::util::URL aUrl;
102 aUrl.Complete =OUString(".uno:DSBEditDoc");
103 GetView()->getController().dispatch( aUrl,Sequence< PropertyValue >() );
106 EditBrowseBox::KeyInput(rEvt);
109 //------------------------------------------------------------------------
110 void OTableRowView::SetUpdatable( sal_Bool bUpdate )
112 m_bUpdatable = bUpdate;
116 //------------------------------------------------------------------------
117 void OTableRowView::Command(const CommandEvent& rEvt)
120 switch (rEvt.GetCommand())
122 case COMMAND_CONTEXTMENU:
124 if (!rEvt.IsMouseEvent())
126 EditBrowseBox::Command(rEvt);
127 return;
130 sal_uInt16 nColId = GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X());
131 long nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
133 if ( nColId == HANDLE_ID )
135 PopupMenu aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
136 long nSelectRowCount = GetSelectRowCount();
137 aContextMenu.EnableItem( SID_CUT, nSelectRowCount != 0);
138 aContextMenu.EnableItem( SID_COPY, nSelectRowCount != 0);
139 aContextMenu.EnableItem( SID_PASTE, m_bClipboardFilled );
140 aContextMenu.EnableItem( SID_DELETE, IsUpdatable() && nSelectRowCount != 0 );
141 switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
143 case SID_CUT:
144 cut();
145 break;
146 case SID_COPY:
147 copy();
148 break;
149 case SID_PASTE:
150 Paste( nRow );
151 SetNoSelection();
152 GoToRow( nRow );
153 SeekRow( nRow );
154 break;
156 case SID_DELETE:
157 DeleteRows();
158 break;
159 case SID_TABLEDESIGN_INSERTROWS:
160 InsertNewRows( nRow );
161 SetNoSelection();
162 GoToRow( nRow );
163 SeekRow( nRow );
164 break;
165 default:
166 break;
171 default:
172 EditBrowseBox::Command(rEvt);
177 //------------------------------------------------------------------------------
178 void OTableRowView::cut()
180 CopyRows();
181 DeleteRows();
184 //------------------------------------------------------------------------------
185 void OTableRowView::copy()
187 CopyRows();
190 //------------------------------------------------------------------------------
191 void OTableRowView::paste()
193 OSL_FAIL("OTableRowView::Paste : (pseudo-) abstract method called !");
196 //------------------------------------------------------------------------------
197 void OTableRowView::Paste( long nRow )
199 InsertRows( nRow );
202 //------------------------------------------------------------------------------
203 EditBrowseBox::RowStatus OTableRowView::GetRowStatus(long nRow) const
205 if (nRow >= 0 && m_nDataPos == nRow)
206 return CURRENT;
207 else
208 return CLEAN;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */