update dev300-m58
[ooovba.git] / dbaccess / source / ui / tabledesign / TableDesignControl.cxx
blob317f50750da1cfb2464cd5d859fc71e0353cbc2d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableDesignControl.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBAUI_TABLEDESIGNCONTROL_HXX
35 #include "TableDesignControl.hxx"
36 #endif
37 #ifndef _DBU_TBL_HRC_
38 #include "dbu_tbl.hrc"
39 #endif
40 #ifndef DBAUI_TABLEDESIGNVIEW_HXX
41 #include "TableDesignView.hxx"
42 #endif
43 #ifndef DBUI_TABLECONTROLLER_HXX
44 #include "TableController.hxx"
45 #endif
46 #ifndef DBACCESS_UI_BROWSER_ID_HXX
47 #include "browserids.hxx"
48 #endif
49 #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
50 #include <com/sun/star/util/URL.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
53 #include <com/sun/star/beans/PropertyValue.hpp>
54 #endif
55 #ifndef _DBA_DBACCESS_HELPID_HRC_
56 #include "dbaccess_helpid.hrc"
57 #endif
59 using namespace ::dbaui;
60 using namespace ::svt;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::beans;
63 using namespace ::com::sun::star::util;
64 //--- Defines
65 #define HANDLE_ID 0
67 DBG_NAME(OTableRowView)
68 //------------------------------------------------------------------------
69 OTableRowView::OTableRowView(Window* pParent)
70 :EditBrowseBox(pParent, ModuleRes(RID_DB_TAB_EDITOR),EBBF_NONE,
71 BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_AUTOSIZE_LASTCOL |
72 BROWSER_KEEPSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL)
73 ,m_nDataPos(-1)
74 ,m_nCurrentPos(-1)
75 ,m_nCurUndoActId(0)
76 ,m_bCurrentModified(FALSE)
77 ,m_bUpdatable(FALSE)
78 ,m_bClipboardFilled(FALSE)
80 DBG_CTOR(OTableRowView,NULL);
84 //------------------------------------------------------------------------
85 OTableRowView::~OTableRowView()
88 DBG_DTOR(OTableRowView,NULL);
91 //------------------------------------------------------------------------
92 void OTableRowView::Init()
94 EditBrowseBox::Init();
96 // SetMapMode( MapMode(MAP_TWIP) );
97 // GetDataWindow().SetMapMode( GetMapMode() );
99 Font aFont( GetDataWindow().GetFont() );
100 aFont.SetWeight( WEIGHT_NORMAL );
101 GetDataWindow().SetFont( aFont );
103 // Font fuer die Ueberschriften auf Light setzen
104 aFont = GetFont();
105 aFont.SetWeight( WEIGHT_LIGHT );
106 SetFont(aFont);
108 // HandleColumn, fuer maximal fuenf Ziffern einrichten
109 InsertHandleColumn(static_cast<USHORT>(GetTextWidth('0') * 4)/*, TRUE */);
111 BrowserMode nMode = BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_KEEPSELECTION |
112 BROWSER_HLINESFULL | BROWSER_VLINESFULL | BROWSER_AUTOSIZE_LASTCOL;
113 if (IsUpdatable())
114 nMode |= BROWSER_HIDECURSOR;
116 SetMode(nMode);
119 //------------------------------------------------------------------------
120 void OTableRowView::KeyInput( const KeyEvent& rEvt )
122 if (IsDeleteAllowed(0))
124 if (rEvt.GetKeyCode().GetCode() == KEY_DELETE && // Delete rows
125 !rEvt.GetKeyCode().IsShift() &&
126 !rEvt.GetKeyCode().IsMod1())
128 DeleteRows();
129 return;
131 if( rEvt.GetKeyCode().GetCode() == KEY_F2 )
133 ::com::sun::star::util::URL aUrl;
134 aUrl.Complete =::rtl::OUString::createFromAscii(".uno:DSBEditDoc");
135 GetView()->getController().dispatch( aUrl,Sequence< PropertyValue >() );
138 EditBrowseBox::KeyInput(rEvt);
141 //------------------------------------------------------------------------
142 void OTableRowView::SetUpdatable( BOOL bUpdate )
144 m_bUpdatable = bUpdate;
148 //------------------------------------------------------------------------
149 void OTableRowView::Command(const CommandEvent& rEvt)
152 switch (rEvt.GetCommand())
154 case COMMAND_CONTEXTMENU:
156 if (!rEvt.IsMouseEvent())
158 EditBrowseBox::Command(rEvt);
159 return;
162 USHORT nColId = GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X());
163 long nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
165 if ( nColId == HANDLE_ID )
167 PopupMenu aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
168 long nSelectRowCount = GetSelectRowCount();
169 aContextMenu.EnableItem( SID_CUT, nSelectRowCount != 0);
170 aContextMenu.EnableItem( SID_COPY, nSelectRowCount != 0);
171 aContextMenu.EnableItem( SID_PASTE, m_bClipboardFilled );
172 aContextMenu.EnableItem( SID_DELETE, IsUpdatable() && nSelectRowCount != 0 );
173 switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
175 case SID_CUT:
176 cut();
177 break;
178 case SID_COPY:
179 copy();
180 break;
181 case SID_PASTE:
182 Paste( nRow );
183 SetNoSelection();
184 GoToRow( nRow );
185 SeekRow( nRow );
186 break;
188 case SID_DELETE:
189 DeleteRows();
190 break;
191 case SID_TABLEDESIGN_INSERTROWS:
192 InsertNewRows( nRow );
193 SetNoSelection();
194 GoToRow( nRow );
195 SeekRow( nRow );
196 break;
197 default:
198 break;
203 default:
204 EditBrowseBox::Command(rEvt);
209 //------------------------------------------------------------------------------
210 void OTableRowView::cut()
212 CopyRows();
213 DeleteRows();
216 //------------------------------------------------------------------------------
217 void OTableRowView::copy()
219 CopyRows();
222 //------------------------------------------------------------------------------
223 void OTableRowView::paste()
225 OSL_ENSURE(0,"OTableRowView::Paste : (pseudo-) abstract method called !");
228 //------------------------------------------------------------------------------
229 void OTableRowView::Paste( long nRow )
231 InsertRows( nRow );
234 //------------------------------------------------------------------------------
235 EditBrowseBox::RowStatus OTableRowView::GetRowStatus(long nRow) const
237 if (nRow >= 0 && m_nDataPos == nRow)
238 return CURRENT;
239 else
240 return CLEAN;