1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef DBAUI_TABLEDESIGNCONTROL_HXX
28cdf0e10cSrcweir #include "TableDesignControl.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _DBU_TBL_HRC_
31cdf0e10cSrcweir #include "dbu_tbl.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef DBAUI_TABLEDESIGNVIEW_HXX
34cdf0e10cSrcweir #include "TableDesignView.hxx"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef DBUI_TABLECONTROLLER_HXX
37cdf0e10cSrcweir #include "TableController.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
40cdf0e10cSrcweir #include "browserids.hxx"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
43cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
46cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
49cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir 
52cdf0e10cSrcweir using namespace ::dbaui;
53cdf0e10cSrcweir using namespace ::svt;
54cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55cdf0e10cSrcweir using namespace ::com::sun::star::beans;
56cdf0e10cSrcweir using namespace ::com::sun::star::util;
57cdf0e10cSrcweir //--- Defines
58cdf0e10cSrcweir #define HANDLE_ID 0
59cdf0e10cSrcweir 
DBG_NAME(OTableRowView)60cdf0e10cSrcweir DBG_NAME(OTableRowView)
61cdf0e10cSrcweir //------------------------------------------------------------------------
62cdf0e10cSrcweir OTableRowView::OTableRowView(Window* pParent)
63cdf0e10cSrcweir     :EditBrowseBox(pParent, ModuleRes(RID_DB_TAB_EDITOR),EBBF_NONE,
64cdf0e10cSrcweir 				    BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_AUTOSIZE_LASTCOL |
65cdf0e10cSrcweir 				    BROWSER_KEEPSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL)
66cdf0e10cSrcweir     ,m_nDataPos(-1)
67cdf0e10cSrcweir     ,m_nCurrentPos(-1)
68cdf0e10cSrcweir     ,m_nCurUndoActId(0)
69cdf0e10cSrcweir     ,m_bCurrentModified(sal_False)
70cdf0e10cSrcweir     ,m_bUpdatable(sal_False)
71cdf0e10cSrcweir     ,m_bClipboardFilled(sal_False)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     DBG_CTOR(OTableRowView,NULL);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir //------------------------------------------------------------------------
~OTableRowView()78cdf0e10cSrcweir OTableRowView::~OTableRowView()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     DBG_DTOR(OTableRowView,NULL);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //------------------------------------------------------------------------
Init()85cdf0e10cSrcweir void OTableRowView::Init()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	EditBrowseBox::Init();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir //	SetMapMode( MapMode(MAP_TWIP) );
90cdf0e10cSrcweir //	GetDataWindow().SetMapMode( GetMapMode() );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	Font aFont( GetDataWindow().GetFont() );
93cdf0e10cSrcweir 	aFont.SetWeight( WEIGHT_NORMAL );
94cdf0e10cSrcweir 	GetDataWindow().SetFont( aFont );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	// Font fuer die Ueberschriften auf Light setzen
97cdf0e10cSrcweir 	aFont = GetFont();
98cdf0e10cSrcweir 	aFont.SetWeight( WEIGHT_LIGHT );
99cdf0e10cSrcweir 	SetFont(aFont);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	// HandleColumn, fuer maximal fuenf Ziffern einrichten
102cdf0e10cSrcweir 	InsertHandleColumn(static_cast<sal_uInt16>(GetTextWidth('0') * 4)/*, sal_True */);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	BrowserMode nMode = BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_KEEPSELECTION |
105cdf0e10cSrcweir 						BROWSER_HLINESFULL | BROWSER_VLINESFULL | BROWSER_AUTOSIZE_LASTCOL;
106cdf0e10cSrcweir 	if (IsUpdatable())
107cdf0e10cSrcweir 		nMode |= BROWSER_HIDECURSOR;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	SetMode(nMode);
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //------------------------------------------------------------------------
KeyInput(const KeyEvent & rEvt)113cdf0e10cSrcweir void OTableRowView::KeyInput( const KeyEvent& rEvt )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	if (IsDeleteAllowed(0))
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		if (rEvt.GetKeyCode().GetCode() == KEY_DELETE &&	// Delete rows
118cdf0e10cSrcweir 			!rEvt.GetKeyCode().IsShift() &&
119cdf0e10cSrcweir 			!rEvt.GetKeyCode().IsMod1())
120cdf0e10cSrcweir 		{
121cdf0e10cSrcweir 			DeleteRows();
122cdf0e10cSrcweir 			return;
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 		if( rEvt.GetKeyCode().GetCode() == KEY_F2 )
125cdf0e10cSrcweir 		{
126cdf0e10cSrcweir 			::com::sun::star::util::URL aUrl;
127cdf0e10cSrcweir 			aUrl.Complete =::rtl::OUString::createFromAscii(".uno:DSBEditDoc");
128cdf0e10cSrcweir 			GetView()->getController().dispatch( aUrl,Sequence< PropertyValue >() );
129cdf0e10cSrcweir 		}
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 	EditBrowseBox::KeyInput(rEvt);
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir //------------------------------------------------------------------------
SetUpdatable(sal_Bool bUpdate)135cdf0e10cSrcweir void OTableRowView::SetUpdatable( sal_Bool bUpdate )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	m_bUpdatable = bUpdate;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //------------------------------------------------------------------------
Command(const CommandEvent & rEvt)142cdf0e10cSrcweir void OTableRowView::Command(const CommandEvent& rEvt)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	switch (rEvt.GetCommand())
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		case COMMAND_CONTEXTMENU:
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			if (!rEvt.IsMouseEvent())
150cdf0e10cSrcweir 			{
151cdf0e10cSrcweir 				EditBrowseBox::Command(rEvt);
152cdf0e10cSrcweir 				return;
153cdf0e10cSrcweir 			}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 			sal_uInt16 nColId = GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X());
156cdf0e10cSrcweir 			long   nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 			if ( nColId == HANDLE_ID )
159cdf0e10cSrcweir 			{
160cdf0e10cSrcweir 				PopupMenu aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
161cdf0e10cSrcweir 				long nSelectRowCount = GetSelectRowCount();
162cdf0e10cSrcweir 				aContextMenu.EnableItem( SID_CUT, nSelectRowCount != 0);
163cdf0e10cSrcweir 				aContextMenu.EnableItem( SID_COPY, nSelectRowCount  != 0);
164cdf0e10cSrcweir 				aContextMenu.EnableItem( SID_PASTE, m_bClipboardFilled );
165cdf0e10cSrcweir 				aContextMenu.EnableItem( SID_DELETE, IsUpdatable() && nSelectRowCount != 0 );
166cdf0e10cSrcweir 				switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
167cdf0e10cSrcweir 				{
168cdf0e10cSrcweir 					case SID_CUT:
169cdf0e10cSrcweir 						cut();
170cdf0e10cSrcweir 						break;
171cdf0e10cSrcweir 					case SID_COPY:
172cdf0e10cSrcweir 						copy();
173cdf0e10cSrcweir 						break;
174cdf0e10cSrcweir 					case SID_PASTE:
175cdf0e10cSrcweir 						Paste( nRow );
176cdf0e10cSrcweir 						SetNoSelection();
177cdf0e10cSrcweir 						GoToRow( nRow );
178cdf0e10cSrcweir 						SeekRow( nRow );
179cdf0e10cSrcweir 						break;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 					case SID_DELETE:
182cdf0e10cSrcweir 						DeleteRows();
183cdf0e10cSrcweir 						break;
184cdf0e10cSrcweir 					case SID_TABLEDESIGN_INSERTROWS:
185cdf0e10cSrcweir 						InsertNewRows( nRow );
186cdf0e10cSrcweir 						SetNoSelection();
187cdf0e10cSrcweir 						GoToRow( nRow );
188cdf0e10cSrcweir 						SeekRow( nRow );
189cdf0e10cSrcweir 						break;
190cdf0e10cSrcweir 					default:
191cdf0e10cSrcweir 						break;
192cdf0e10cSrcweir 				}
193cdf0e10cSrcweir 			}
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 		}
196cdf0e10cSrcweir 		default:
197cdf0e10cSrcweir 			EditBrowseBox::Command(rEvt);
198cdf0e10cSrcweir 	}
199cdf0e10cSrcweir 
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir //------------------------------------------------------------------------------
cut()203cdf0e10cSrcweir void OTableRowView::cut()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	CopyRows();
206cdf0e10cSrcweir 	DeleteRows();
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //------------------------------------------------------------------------------
copy()210cdf0e10cSrcweir void OTableRowView::copy()
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	CopyRows();
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //------------------------------------------------------------------------------
paste()216cdf0e10cSrcweir void OTableRowView::paste()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	OSL_ENSURE(0,"OTableRowView::Paste : (pseudo-) abstract method called !");
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //------------------------------------------------------------------------------
Paste(long nRow)222cdf0e10cSrcweir void OTableRowView::Paste( long nRow )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	InsertRows( nRow );
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir //------------------------------------------------------------------------------
GetRowStatus(long nRow) const228cdf0e10cSrcweir EditBrowseBox::RowStatus OTableRowView::GetRowStatus(long nRow) const
229cdf0e10cSrcweir {
230cdf0e10cSrcweir 	if (nRow >= 0 && m_nDataPos == nRow)
231cdf0e10cSrcweir 		return CURRENT;
232cdf0e10cSrcweir 	else
233cdf0e10cSrcweir 		return CLEAN;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 
238