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