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