1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableDesignView.cxx,v $
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"
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
39 #ifndef DBUI_TABLECONTROLLER_HXX
40 #include "TableController.hxx"
42 #ifndef _DBA_DBACCESS_HELPID_HRC_
43 #include "dbaccess_helpid.hrc"
45 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
46 #include "FieldDescriptions.hxx"
48 #ifndef DBAUI_TABLEEDITORCONTROL_HXX
49 #include "TEditControl.hxx"
51 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX
52 #include "TableFieldDescWin.hxx"
54 #ifndef DBAUI_TABLEROW_HXX
55 #include "TableRow.hxx"
57 #ifndef _UTL_CONFIGMGR_HXX_
58 #include <unotools/configmgr.hxx>
60 #ifndef _COMPHELPER_TYPES_HXX_
61 #include <comphelper/types.hxx>
63 #ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARD_HPP_
64 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
66 #ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX
67 #include <svtools/syslocale.hxx>
69 #ifndef DBAUI_TOOLS_HXX
70 #include "UITools.hxx"
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 //////////////////////////////////////////////////////////////////////
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 //////////////////////////////////////////////////////////////////////
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 //////////////////////////////////////////////////////////////////////
148 m_aHorzSplitter
.SetPosSizePixel( Point( 0, nSplitPos
), Size(nOutputWidth
, nSplitterHeight
));
149 m_aHorzSplitter
.SetSplitPosPixel( nSplitPos
);
151 //////////////////////////////////////////////////////////////////////
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() ) );
168 // -----------------------------------------------------------------------------
169 void OTableBorderWindow::ImplInitSettings( sal_Bool bFont
, sal_Bool bForeground
, sal_Bool bBackground
)
171 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
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
);
192 if( IsControlBackground() )
193 SetBackground( GetControlBackground() );
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
);
210 // -----------------------------------------------------------------------------
211 void OTableBorderWindow::GetFocus()
215 // forward the focus to the current cell of the editor control
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
)
233 DBG_CTOR(OTableDesignView
,NULL
);
237 m_aLocale
= SvtSysLocale().GetLocaleData().getLocale();
243 m_pWin
= new OTableBorderWindow(this);
247 //------------------------------------------------------------------------------
248 OTableDesignView::~OTableDesignView()
250 DBG_DTOR(OTableDesignView
,NULL
);
254 ::std::auto_ptr
<Window
> aTemp(m_pWin
);
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() )
289 if( GetDescWin()->HasChildPathFocus() )
291 GetDescWin()->LoseFocus();
292 GetEditorCtrl()->GrabFocus();
296 ::boost::shared_ptr
<OTableRow
> pRow
= (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
297 OFieldDescription
* pFieldDescr
= pRow
? pRow
->GetActFieldDescr() : NULL
;
299 GetDescWin()->GrabFocus();
301 GetEditorCtrl()->GrabFocus();
306 //------------------------------------------------------------------------------
307 long OTableDesignView::PreNotify( NotifyEvent
& rNEvt
)
309 BOOL bHandled
= FALSE
;
310 switch(rNEvt
.GetType())
313 if( GetDescWin() && GetDescWin()->HasChildPathFocus() )
314 m_eChildFocus
= DESCRIPTION
;
315 else if ( GetEditorCtrl() && GetEditorCtrl()->HasChildPathFocus() )
316 m_eChildFocus
= EDITOR
;
318 m_eChildFocus
= NONE
;
322 return bHandled
? 1L : ODataView::PreNotify(rNEvt
);
324 // -----------------------------------------------------------------------------
325 IClipboardTest
* OTableDesignView::getActiveChild() const
327 IClipboardTest
* pTest
= NULL
;
328 switch(m_eChildFocus
)
331 pTest
= GetDescWin();
334 pTest
= GetEditorCtrl();
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();
366 // -----------------------------------------------------------------------------
367 void OTableDesignView::cut()
369 IClipboardTest
* pTest
= getActiveChild();
373 // -----------------------------------------------------------------------------
374 void OTableDesignView::paste()
376 IClipboardTest
* pTest
= getActiveChild();
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
;
394 GetDescWin()->DisplayData(pFieldDescr
);
396 // -----------------------------------------------------------------------------
397 void OTableDesignView::GetFocus()
399 if ( GetEditorCtrl() )
400 GetEditorCtrl()->GrabFocus();
402 // -----------------------------------------------------------------------------