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