xref: /trunk/main/dbaccess/source/ui/tabledesign/TableDesignView.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef DBAUI_TABLEDESIGNVIEW_HXX
31 #include "TableDesignView.hxx"
32 #endif
33 #ifndef _TOOLS_DEBUG_HXX
34 #include <tools/debug.hxx>
35 #endif
36 #ifndef DBUI_TABLECONTROLLER_HXX
37 #include "TableController.hxx"
38 #endif
39 #ifndef _DBA_DBACCESS_HELPID_HRC_
40 #include "dbaccess_helpid.hrc"
41 #endif
42 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
43 #include "FieldDescriptions.hxx"
44 #endif
45 #ifndef DBAUI_TABLEEDITORCONTROL_HXX
46 #include "TEditControl.hxx"
47 #endif
48 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX
49 #include "TableFieldDescWin.hxx"
50 #endif
51 #ifndef DBAUI_TABLEROW_HXX
52 #include "TableRow.hxx"
53 #endif
54 #ifndef _UTL_CONFIGMGR_HXX_
55 #include <unotools/configmgr.hxx>
56 #endif
57 #ifndef _COMPHELPER_TYPES_HXX_
58 #include <comphelper/types.hxx>
59 #endif
60 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARD_HPP_
61 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
62 #endif
63 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
64 #include <unotools/syslocale.hxx>
65 #endif
66 #ifndef DBAUI_TOOLS_HXX
67 #include "UITools.hxx"
68 #endif
69 
70 
71 using namespace ::dbaui;
72 using namespace ::utl;
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::datatransfer::clipboard;
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::beans;
77 
78 //==================================================================
79 // class OTableBorderWindow
80 DBG_NAME(OTableBorderWindow)
81 //==================================================================
82 OTableBorderWindow::OTableBorderWindow(Window* pParent) : Window(pParent,WB_BORDER)
83     ,m_aHorzSplitter( this )
84 {
85     DBG_CTOR(OTableBorderWindow,NULL);
86 
87     ImplInitSettings( sal_True, sal_True, sal_True );
88     //////////////////////////////////////////////////////////////////////
89     // Childs erzeugen
90     m_pEditorCtrl   = new OTableEditorCtrl( this);
91     m_pFieldDescWin = new OTableFieldDescWin( this );
92 
93     m_pFieldDescWin->SetHelpId(HID_TAB_DESIGN_DESCWIN);
94 
95     // set depending windows and controls
96     m_pEditorCtrl->SetDescrWin(m_pFieldDescWin);
97 
98     //////////////////////////////////////////////////////////////////////
99     // Splitter einrichten
100     m_aHorzSplitter.SetSplitHdl( LINK(this, OTableBorderWindow, SplitHdl) );
101     m_aHorzSplitter.Show();
102 }
103 // -----------------------------------------------------------------------------
104 OTableBorderWindow::~OTableBorderWindow()
105 {
106     //////////////////////////////////////////////////////////////////////
107     // Childs zerstoeren
108     //  ::dbaui::notifySystemWindow(this,m_pFieldDescWin,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
109     m_pEditorCtrl->Hide();
110     m_pFieldDescWin->Hide();
111 
112     {
113         ::std::auto_ptr<Window> aTemp(m_pEditorCtrl);
114         m_pEditorCtrl = NULL;
115     }
116     {
117         ::std::auto_ptr<Window> aTemp(m_pFieldDescWin);
118         m_pFieldDescWin = NULL;
119     }
120 
121     DBG_DTOR(OTableBorderWindow,NULL);
122 }
123 // -----------------------------------------------------------------------------
124 void OTableBorderWindow::Resize()
125 {
126     const long nSplitterHeight(3);
127 
128     //////////////////////////////////////////////////////////////////////
129     // Abmessungen parent window
130     Size aOutputSize( GetOutputSize() );
131     long nOutputWidth   = aOutputSize.Width();
132     long nOutputHeight  = aOutputSize.Height();
133     long nSplitPos      = m_aHorzSplitter.GetSplitPosPixel();
134 
135     //////////////////////////////////////////////////////////////////////
136     // Verschiebebereich Splitter mittleres Drittel des Outputs
137     long nDragPosY = nOutputHeight/3;
138     long nDragSizeHeight = nOutputHeight/3;
139     m_aHorzSplitter.SetDragRectPixel( Rectangle(Point(0,nDragPosY), Size(nOutputWidth,nDragSizeHeight) ), this );
140     if( (nSplitPos < nDragPosY) || (nSplitPos > (nDragPosY+nDragSizeHeight)) )
141         nSplitPos = nDragPosY+nDragSizeHeight-5;
142 
143     //////////////////////////////////////////////////////////////////////
144     // Splitter setzen
145     m_aHorzSplitter.SetPosSizePixel( Point( 0, nSplitPos ), Size(nOutputWidth, nSplitterHeight));
146     m_aHorzSplitter.SetSplitPosPixel( nSplitPos );
147 
148     //////////////////////////////////////////////////////////////////////
149     // Fenster setzen
150     m_pEditorCtrl->SetPosSizePixel( Point(0, 0), Size(nOutputWidth , nSplitPos) );
151 
152     m_pFieldDescWin->SetPosSizePixel(   Point(0, nSplitPos+nSplitterHeight),
153                         Size(nOutputWidth, nOutputHeight-nSplitPos-nSplitterHeight) );
154 }
155 //------------------------------------------------------------------------------
156 IMPL_LINK( OTableBorderWindow, SplitHdl, Splitter*, pSplit )
157 {
158     if(pSplit == &m_aHorzSplitter)
159     {
160         m_aHorzSplitter.SetPosPixel( Point( m_aHorzSplitter.GetPosPixel().X(),m_aHorzSplitter.GetSplitPosPixel() ) );
161         Resize();
162     }
163     return 0;
164 }
165 // -----------------------------------------------------------------------------
166 void OTableBorderWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
167 {
168     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
169 
170     if ( bFont )
171     {
172         Font aFont = rStyleSettings.GetAppFont();
173         if ( IsControlFont() )
174             aFont.Merge( GetControlFont() );
175         SetPointFont( aFont );
176 //      Set/*Zoomed*/PointFont( aFont );
177     }
178 
179     if ( bFont || bForeground )
180     {
181         Color aTextColor = rStyleSettings.GetButtonTextColor();
182         if ( IsControlForeground() )
183             aTextColor = GetControlForeground();
184         SetTextColor( aTextColor );
185     }
186 
187     if ( bBackground )
188     {
189         if( IsControlBackground() )
190             SetBackground( GetControlBackground() );
191         else
192             SetBackground( rStyleSettings.GetFaceColor() );
193     }
194 }
195 // -----------------------------------------------------------------------
196 void OTableBorderWindow::DataChanged( const DataChangedEvent& rDCEvt )
197 {
198     Window::DataChanged( rDCEvt );
199 
200     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
201          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
202     {
203         ImplInitSettings( sal_True, sal_True, sal_True );
204         Invalidate();
205     }
206 }
207 // -----------------------------------------------------------------------------
208 void OTableBorderWindow::GetFocus()
209 {
210     Window::GetFocus();
211 
212     // forward the focus to the current cell of the editor control
213     if (m_pEditorCtrl)
214         m_pEditorCtrl->GrabFocus();
215 }
216 
217 //==================================================================
218 // class OTableDesignView
219 //==================================================================
220 DBG_NAME(OTableDesignView);
221 //------------------------------------------------------------------------------
222 OTableDesignView::OTableDesignView( Window* pParent,
223                                     const Reference< XMultiServiceFactory >& _rxOrb,
224                                     OTableController& _rController
225                                    ) :
226     ODataView( pParent, _rController,_rxOrb )
227     ,m_rController( _rController )
228     ,m_eChildFocus(NONE)
229 {
230     DBG_CTOR(OTableDesignView,NULL);
231 
232     try
233     {
234         m_aLocale = SvtSysLocale().GetLocaleData().getLocale();
235     }
236     catch(Exception&)
237     {
238     }
239 
240     m_pWin = new OTableBorderWindow(this);
241     m_pWin->Show();
242 }
243 
244 //------------------------------------------------------------------------------
245 OTableDesignView::~OTableDesignView()
246 {
247     DBG_DTOR(OTableDesignView,NULL);
248     m_pWin->Hide();
249 
250     {
251         ::std::auto_ptr<Window> aTemp(m_pWin);
252         m_pWin = NULL;
253     }
254 }
255 
256 // -----------------------------------------------------------------------------
257 void OTableDesignView::initialize()
258 {
259     GetEditorCtrl()->Init();
260     GetDescWin()->Init();
261     // first call after the editctrl has been set
262 
263     GetEditorCtrl()->Show();
264     GetDescWin()->Show();
265 
266     GetEditorCtrl()->DisplayData(0);
267 }
268 //------------------------------------------------------------------------------
269 
270 //------------------------------------------------------------------------------
271 void OTableDesignView::resizeDocumentView(Rectangle& _rPlayground)
272 {
273     m_pWin->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
274 
275     // just for completeness: there is no space left, we occupied it all ...
276     _rPlayground.SetPos( _rPlayground.BottomRight() );
277     _rPlayground.SetSize( Size( 0, 0 ) );
278 }
279 
280 //------------------------------------------------------------------------------
281 IMPL_LINK( OTableDesignView, SwitchHdl, Accelerator*, /*pAcc*/ )
282 {
283     if( getController().isReadOnly() )
284         return 0;
285 
286     if( GetDescWin()->HasChildPathFocus() )
287     {
288         GetDescWin()->LoseFocus();
289         GetEditorCtrl()->GrabFocus();
290     }
291     else
292     {
293          ::boost::shared_ptr<OTableRow>  pRow = (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
294         OFieldDescription* pFieldDescr = pRow ? pRow->GetActFieldDescr() : NULL;
295         if ( pFieldDescr )
296             GetDescWin()->GrabFocus();
297         else
298             GetEditorCtrl()->GrabFocus();
299     }
300 
301     return 0;
302 }
303 //------------------------------------------------------------------------------
304 long OTableDesignView::PreNotify( NotifyEvent& rNEvt )
305 {
306     sal_Bool bHandled = sal_False;
307     switch(rNEvt.GetType())
308     {
309         case EVENT_GETFOCUS:
310             if( GetDescWin() && GetDescWin()->HasChildPathFocus() )
311                 m_eChildFocus = DESCRIPTION;
312             else if ( GetEditorCtrl() && GetEditorCtrl()->HasChildPathFocus() )
313                 m_eChildFocus = EDITOR;
314             else
315                 m_eChildFocus = NONE;
316             break;
317     }
318 
319     return bHandled ? 1L : ODataView::PreNotify(rNEvt);
320 }
321 // -----------------------------------------------------------------------------
322 IClipboardTest* OTableDesignView::getActiveChild() const
323 {
324     IClipboardTest* pTest = NULL;
325     switch(m_eChildFocus)
326     {
327         case DESCRIPTION:
328             pTest = GetDescWin();
329             break;
330         case EDITOR:
331             pTest = GetEditorCtrl();
332             break;
333         case NONE:
334             break;
335     }
336     return pTest;
337 }
338 // -----------------------------------------------------------------------------
339 sal_Bool OTableDesignView::isCopyAllowed()
340 {
341     IClipboardTest* pTest = getActiveChild();
342     return pTest && pTest->isCopyAllowed();
343 }
344 // -----------------------------------------------------------------------------
345 sal_Bool OTableDesignView::isCutAllowed()
346 {
347     IClipboardTest* pTest = getActiveChild();
348     return pTest && pTest->isCutAllowed();
349 }
350 // -----------------------------------------------------------------------------
351 sal_Bool OTableDesignView::isPasteAllowed()
352 {
353     IClipboardTest* pTest = getActiveChild();
354     return pTest && pTest->isPasteAllowed();
355 }
356 // -----------------------------------------------------------------------------
357 void OTableDesignView::copy()
358 {
359     IClipboardTest* pTest = getActiveChild();
360     if ( pTest )
361         pTest->copy();
362 }
363 // -----------------------------------------------------------------------------
364 void OTableDesignView::cut()
365 {
366     IClipboardTest* pTest = getActiveChild();
367     if ( pTest )
368         pTest->cut();
369 }
370 // -----------------------------------------------------------------------------
371 void OTableDesignView::paste()
372 {
373     IClipboardTest* pTest = getActiveChild();
374     if ( pTest )
375         pTest->paste();
376 }
377 // -----------------------------------------------------------------------------
378 // set the view readonly or not
379 void OTableDesignView::setReadOnly(sal_Bool _bReadOnly)
380 {
381     GetDescWin()->SetReadOnly(_bReadOnly);
382     GetEditorCtrl()->SetReadOnly(_bReadOnly);
383 }
384 // -----------------------------------------------------------------------------
385 void OTableDesignView::reSync()
386 {
387     GetEditorCtrl()->DeactivateCell();
388      ::boost::shared_ptr<OTableRow>  pRow = (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
389     OFieldDescription* pFieldDescr = pRow ? pRow->GetActFieldDescr() : NULL;
390     if ( pFieldDescr )
391         GetDescWin()->DisplayData(pFieldDescr);
392 }
393 // -----------------------------------------------------------------------------
394 void OTableDesignView::GetFocus()
395 {
396     if ( GetEditorCtrl() )
397         GetEditorCtrl()->GrabFocus();
398 }
399 // -----------------------------------------------------------------------------
400 
401