update dev300-m58
[ooovba.git] / dbaccess / source / ui / tabledesign / TableDesignView.cxx
blobf38c5bcf8cd0683ee640aa225fd86d88419b47e9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableDesignView.cxx,v $
10 * $Revision: 1.32 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_TABLEDESIGNVIEW_HXX
34 #include "TableDesignView.hxx"
35 #endif
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
38 #endif
39 #ifndef DBUI_TABLECONTROLLER_HXX
40 #include "TableController.hxx"
41 #endif
42 #ifndef _DBA_DBACCESS_HELPID_HRC_
43 #include "dbaccess_helpid.hrc"
44 #endif
45 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
46 #include "FieldDescriptions.hxx"
47 #endif
48 #ifndef DBAUI_TABLEEDITORCONTROL_HXX
49 #include "TEditControl.hxx"
50 #endif
51 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX
52 #include "TableFieldDescWin.hxx"
53 #endif
54 #ifndef DBAUI_TABLEROW_HXX
55 #include "TableRow.hxx"
56 #endif
57 #ifndef _UTL_CONFIGMGR_HXX_
58 #include <unotools/configmgr.hxx>
59 #endif
60 #ifndef _COMPHELPER_TYPES_HXX_
61 #include <comphelper/types.hxx>
62 #endif
63 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARD_HPP_
64 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
65 #endif
66 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
67 #include <svtools/syslocale.hxx>
68 #endif
69 #ifndef DBAUI_TOOLS_HXX
70 #include "UITools.hxx"
71 #endif
74 using namespace ::dbaui;
75 using namespace ::utl;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::datatransfer::clipboard;
78 using namespace ::com::sun::star::lang;
79 using namespace ::com::sun::star::beans;
81 //==================================================================
82 // class OTableBorderWindow
83 DBG_NAME(OTableBorderWindow)
84 //==================================================================
85 OTableBorderWindow::OTableBorderWindow(Window* pParent) : Window(pParent,WB_BORDER)
86 ,m_aHorzSplitter( this )
88 DBG_CTOR(OTableBorderWindow,NULL);
90 ImplInitSettings( sal_True, sal_True, sal_True );
91 //////////////////////////////////////////////////////////////////////
92 // Childs erzeugen
93 m_pEditorCtrl = new OTableEditorCtrl( this);
94 m_pFieldDescWin = new OTableFieldDescWin( this );
96 m_pFieldDescWin->SetHelpId(HID_TAB_DESIGN_DESCWIN);
98 // set depending windows and controls
99 m_pEditorCtrl->SetDescrWin(m_pFieldDescWin);
101 //////////////////////////////////////////////////////////////////////
102 // Splitter einrichten
103 m_aHorzSplitter.SetSplitHdl( LINK(this, OTableBorderWindow, SplitHdl) );
104 m_aHorzSplitter.Show();
106 // -----------------------------------------------------------------------------
107 OTableBorderWindow::~OTableBorderWindow()
109 //////////////////////////////////////////////////////////////////////
110 // Childs zerstoeren
111 // ::dbaui::notifySystemWindow(this,m_pFieldDescWin,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
112 m_pEditorCtrl->Hide();
113 m_pFieldDescWin->Hide();
116 ::std::auto_ptr<Window> aTemp(m_pEditorCtrl);
117 m_pEditorCtrl = NULL;
120 ::std::auto_ptr<Window> aTemp(m_pFieldDescWin);
121 m_pFieldDescWin = NULL;
124 DBG_DTOR(OTableBorderWindow,NULL);
126 // -----------------------------------------------------------------------------
127 void OTableBorderWindow::Resize()
129 const long nSplitterHeight(3);
131 //////////////////////////////////////////////////////////////////////
132 // Abmessungen parent window
133 Size aOutputSize( GetOutputSize() );
134 long nOutputWidth = aOutputSize.Width();
135 long nOutputHeight = aOutputSize.Height();
136 long nSplitPos = m_aHorzSplitter.GetSplitPosPixel();
138 //////////////////////////////////////////////////////////////////////
139 // Verschiebebereich Splitter mittleres Drittel des Outputs
140 long nDragPosY = nOutputHeight/3;
141 long nDragSizeHeight = nOutputHeight/3;
142 m_aHorzSplitter.SetDragRectPixel( Rectangle(Point(0,nDragPosY), Size(nOutputWidth,nDragSizeHeight) ), this );
143 if( (nSplitPos < nDragPosY) || (nSplitPos > (nDragPosY+nDragSizeHeight)) )
144 nSplitPos = nDragPosY+nDragSizeHeight-5;
146 //////////////////////////////////////////////////////////////////////
147 // Splitter setzen
148 m_aHorzSplitter.SetPosSizePixel( Point( 0, nSplitPos ), Size(nOutputWidth, nSplitterHeight));
149 m_aHorzSplitter.SetSplitPosPixel( nSplitPos );
151 //////////////////////////////////////////////////////////////////////
152 // Fenster setzen
153 m_pEditorCtrl->SetPosSizePixel( Point(0, 0), Size(nOutputWidth , nSplitPos) );
155 m_pFieldDescWin->SetPosSizePixel( Point(0, nSplitPos+nSplitterHeight),
156 Size(nOutputWidth, nOutputHeight-nSplitPos-nSplitterHeight) );
158 //------------------------------------------------------------------------------
159 IMPL_LINK( OTableBorderWindow, SplitHdl, Splitter*, pSplit )
161 if(pSplit == &m_aHorzSplitter)
163 m_aHorzSplitter.SetPosPixel( Point( m_aHorzSplitter.GetPosPixel().X(),m_aHorzSplitter.GetSplitPosPixel() ) );
164 Resize();
166 return 0;
168 // -----------------------------------------------------------------------------
169 void OTableBorderWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
171 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
173 if ( bFont )
175 Font aFont = rStyleSettings.GetAppFont();
176 if ( IsControlFont() )
177 aFont.Merge( GetControlFont() );
178 SetPointFont( aFont );
179 // Set/*Zoomed*/PointFont( aFont );
182 if ( bFont || bForeground )
184 Color aTextColor = rStyleSettings.GetButtonTextColor();
185 if ( IsControlForeground() )
186 aTextColor = GetControlForeground();
187 SetTextColor( aTextColor );
190 if ( bBackground )
192 if( IsControlBackground() )
193 SetBackground( GetControlBackground() );
194 else
195 SetBackground( rStyleSettings.GetFaceColor() );
198 // -----------------------------------------------------------------------
199 void OTableBorderWindow::DataChanged( const DataChangedEvent& rDCEvt )
201 Window::DataChanged( rDCEvt );
203 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
204 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
206 ImplInitSettings( sal_True, sal_True, sal_True );
207 Invalidate();
210 // -----------------------------------------------------------------------------
211 void OTableBorderWindow::GetFocus()
213 Window::GetFocus();
215 // forward the focus to the current cell of the editor control
216 if (m_pEditorCtrl)
217 m_pEditorCtrl->GrabFocus();
220 //==================================================================
221 // class OTableDesignView
222 //==================================================================
223 DBG_NAME(OTableDesignView);
224 //------------------------------------------------------------------------------
225 OTableDesignView::OTableDesignView( Window* pParent,
226 const Reference< XMultiServiceFactory >& _rxOrb,
227 OTableController& _rController
229 ODataView( pParent, _rController,_rxOrb )
230 ,m_rController( _rController )
231 ,m_eChildFocus(NONE)
233 DBG_CTOR(OTableDesignView,NULL);
237 m_aLocale = SvtSysLocale().GetLocaleData().getLocale();
239 catch(Exception&)
243 m_pWin = new OTableBorderWindow(this);
244 m_pWin->Show();
247 //------------------------------------------------------------------------------
248 OTableDesignView::~OTableDesignView()
250 DBG_DTOR(OTableDesignView,NULL);
251 m_pWin->Hide();
254 ::std::auto_ptr<Window> aTemp(m_pWin);
255 m_pWin = NULL;
259 // -----------------------------------------------------------------------------
260 void OTableDesignView::initialize()
262 GetEditorCtrl()->Init();
263 GetDescWin()->Init();
264 // first call after the editctrl has been set
266 GetEditorCtrl()->Show();
267 GetDescWin()->Show();
269 GetEditorCtrl()->DisplayData(0);
271 //------------------------------------------------------------------------------
273 //------------------------------------------------------------------------------
274 void OTableDesignView::resizeDocumentView(Rectangle& _rPlayground)
276 m_pWin->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
278 // just for completeness: there is no space left, we occupied it all ...
279 _rPlayground.SetPos( _rPlayground.BottomRight() );
280 _rPlayground.SetSize( Size( 0, 0 ) );
283 //------------------------------------------------------------------------------
284 IMPL_LINK( OTableDesignView, SwitchHdl, Accelerator*, /*pAcc*/ )
286 if( getController().isReadOnly() )
287 return 0;
289 if( GetDescWin()->HasChildPathFocus() )
291 GetDescWin()->LoseFocus();
292 GetEditorCtrl()->GrabFocus();
294 else
296 ::boost::shared_ptr<OTableRow> pRow = (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
297 OFieldDescription* pFieldDescr = pRow ? pRow->GetActFieldDescr() : NULL;
298 if ( pFieldDescr )
299 GetDescWin()->GrabFocus();
300 else
301 GetEditorCtrl()->GrabFocus();
304 return 0;
306 //------------------------------------------------------------------------------
307 long OTableDesignView::PreNotify( NotifyEvent& rNEvt )
309 BOOL bHandled = FALSE;
310 switch(rNEvt.GetType())
312 case EVENT_GETFOCUS:
313 if( GetDescWin() && GetDescWin()->HasChildPathFocus() )
314 m_eChildFocus = DESCRIPTION;
315 else if ( GetEditorCtrl() && GetEditorCtrl()->HasChildPathFocus() )
316 m_eChildFocus = EDITOR;
317 else
318 m_eChildFocus = NONE;
319 break;
322 return bHandled ? 1L : ODataView::PreNotify(rNEvt);
324 // -----------------------------------------------------------------------------
325 IClipboardTest* OTableDesignView::getActiveChild() const
327 IClipboardTest* pTest = NULL;
328 switch(m_eChildFocus)
330 case DESCRIPTION:
331 pTest = GetDescWin();
332 break;
333 case EDITOR:
334 pTest = GetEditorCtrl();
335 break;
336 case NONE:
337 break;
339 return pTest;
341 // -----------------------------------------------------------------------------
342 sal_Bool OTableDesignView::isCopyAllowed()
344 IClipboardTest* pTest = getActiveChild();
345 return pTest && pTest->isCopyAllowed();
347 // -----------------------------------------------------------------------------
348 sal_Bool OTableDesignView::isCutAllowed()
350 IClipboardTest* pTest = getActiveChild();
351 return pTest && pTest->isCutAllowed();
353 // -----------------------------------------------------------------------------
354 sal_Bool OTableDesignView::isPasteAllowed()
356 IClipboardTest* pTest = getActiveChild();
357 return pTest && pTest->isPasteAllowed();
359 // -----------------------------------------------------------------------------
360 void OTableDesignView::copy()
362 IClipboardTest* pTest = getActiveChild();
363 if ( pTest )
364 pTest->copy();
366 // -----------------------------------------------------------------------------
367 void OTableDesignView::cut()
369 IClipboardTest* pTest = getActiveChild();
370 if ( pTest )
371 pTest->cut();
373 // -----------------------------------------------------------------------------
374 void OTableDesignView::paste()
376 IClipboardTest* pTest = getActiveChild();
377 if ( pTest )
378 pTest->paste();
380 // -----------------------------------------------------------------------------
381 // set the view readonly or not
382 void OTableDesignView::setReadOnly(sal_Bool _bReadOnly)
384 GetDescWin()->SetReadOnly(_bReadOnly);
385 GetEditorCtrl()->SetReadOnly(_bReadOnly);
387 // -----------------------------------------------------------------------------
388 void OTableDesignView::reSync()
390 GetEditorCtrl()->DeactivateCell();
391 ::boost::shared_ptr<OTableRow> pRow = (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
392 OFieldDescription* pFieldDescr = pRow ? pRow->GetActFieldDescr() : NULL;
393 if ( pFieldDescr )
394 GetDescWin()->DisplayData(pFieldDescr);
396 // -----------------------------------------------------------------------------
397 void OTableDesignView::GetFocus()
399 if ( GetEditorCtrl() )
400 GetEditorCtrl()->GrabFocus();
402 // -----------------------------------------------------------------------------