1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "TableDesignView.hxx"
21 #include <tools/debug.hxx>
22 #include "TableController.hxx"
23 #include "dbaccess_helpid.hrc"
24 #include "FieldDescriptions.hxx"
25 #include "TEditControl.hxx"
26 #include "TableFieldDescWin.hxx"
27 #include "TableRow.hxx"
28 #include <unotools/configmgr.hxx>
29 #include <comphelper/types.hxx>
30 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
31 #include <unotools/syslocale.hxx>
32 #include <vcl/settings.hxx>
33 #include "UITools.hxx"
34 #include <boost/scoped_ptr.hpp>
36 using namespace ::dbaui
;
37 using namespace ::utl
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::datatransfer::clipboard
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::beans
;
43 // class OTableBorderWindow
44 OTableBorderWindow::OTableBorderWindow(vcl::Window
* pParent
) : Window(pParent
,WB_BORDER
)
45 ,m_aHorzSplitter( VclPtr
<Splitter
>::Create(this) )
48 ImplInitSettings( true, true, true );
50 m_pEditorCtrl
= VclPtr
<OTableEditorCtrl
>::Create( this);
51 m_pFieldDescWin
= VclPtr
<OTableFieldDescWin
>::Create( this );
53 m_pFieldDescWin
->SetHelpId(HID_TAB_DESIGN_DESCWIN
);
55 // set depending windows and controls
56 m_pEditorCtrl
->SetDescrWin(m_pFieldDescWin
);
58 // Splitter einrichten
59 m_aHorzSplitter
->SetSplitHdl( LINK(this, OTableBorderWindow
, SplitHdl
) );
60 m_aHorzSplitter
->Show();
63 OTableBorderWindow::~OTableBorderWindow()
68 void OTableBorderWindow::dispose()
70 // Children zerstoeren
71 // ::dbaui::notifySystemWindow(this,m_pFieldDescWin,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
72 m_pEditorCtrl
->Hide();
73 m_pFieldDescWin
->Hide();
74 m_pEditorCtrl
.disposeAndClear();
75 m_pFieldDescWin
.disposeAndClear();
76 m_aHorzSplitter
.disposeAndClear();
77 vcl::Window::dispose();
80 void OTableBorderWindow::Resize()
82 const long nSplitterHeight(3);
84 // Abmessungen parent window
85 Size
aOutputSize( GetOutputSize() );
86 long nOutputWidth
= aOutputSize
.Width();
87 long nOutputHeight
= aOutputSize
.Height();
88 long nSplitPos
= m_aHorzSplitter
->GetSplitPosPixel();
90 // Verschiebebereich Splitter mittleres Drittel des Outputs
91 long nDragPosY
= nOutputHeight
/3;
92 long nDragSizeHeight
= nOutputHeight
/3;
93 m_aHorzSplitter
->SetDragRectPixel( Rectangle(Point(0,nDragPosY
), Size(nOutputWidth
,nDragSizeHeight
) ), this );
94 if( (nSplitPos
< nDragPosY
) || (nSplitPos
> (nDragPosY
+nDragSizeHeight
)) )
95 nSplitPos
= nDragPosY
+nDragSizeHeight
-5;
98 m_aHorzSplitter
->SetPosSizePixel( Point( 0, nSplitPos
), Size(nOutputWidth
, nSplitterHeight
));
99 m_aHorzSplitter
->SetSplitPosPixel( nSplitPos
);
102 m_pEditorCtrl
->SetPosSizePixel( Point(0, 0), Size(nOutputWidth
, nSplitPos
) );
104 m_pFieldDescWin
->SetPosSizePixel( Point(0, nSplitPos
+nSplitterHeight
),
105 Size(nOutputWidth
, nOutputHeight
-nSplitPos
-nSplitterHeight
) );
108 IMPL_LINK( OTableBorderWindow
, SplitHdl
, Splitter
*, pSplit
)
110 if(pSplit
== m_aHorzSplitter
.get())
112 m_aHorzSplitter
->SetPosPixel( Point( m_aHorzSplitter
->GetPosPixel().X(),m_aHorzSplitter
->GetSplitPosPixel() ) );
118 void OTableBorderWindow::ImplInitSettings( bool bFont
, bool bForeground
, bool bBackground
)
120 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
122 // FIXME RenderContext
126 vcl::Font aFont
= rStyleSettings
.GetAppFont();
127 if ( IsControlFont() )
128 aFont
.Merge( GetControlFont() );
129 SetPointFont(*this, aFont
);
132 if ( bFont
|| bForeground
)
134 Color aTextColor
= rStyleSettings
.GetButtonTextColor();
135 if ( IsControlForeground() )
136 aTextColor
= GetControlForeground();
137 SetTextColor( aTextColor
);
142 if( IsControlBackground() )
143 SetBackground( GetControlBackground() );
145 SetBackground( rStyleSettings
.GetFaceColor() );
149 void OTableBorderWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
151 Window::DataChanged( rDCEvt
);
153 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
154 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
156 ImplInitSettings( true, true, true );
161 void OTableBorderWindow::GetFocus()
165 // forward the focus to the current cell of the editor control
167 m_pEditorCtrl
->GrabFocus();
170 // class OTableDesignView
171 OTableDesignView::OTableDesignView( vcl::Window
* pParent
,
172 const Reference
< XComponentContext
>& _rxOrb
,
173 OTableController
& _rController
175 ODataView( pParent
, _rController
,_rxOrb
)
176 ,m_rController( _rController
)
182 m_aLocale
= SvtSysLocale().GetLanguageTag().getLocale();
188 m_pWin
= VclPtr
<OTableBorderWindow
>::Create(this);
192 OTableDesignView::~OTableDesignView()
197 void OTableDesignView::dispose()
200 m_pWin
.disposeAndClear();
201 ODataView::dispose();
204 void OTableDesignView::initialize()
206 GetEditorCtrl()->Init();
207 GetDescWin()->Init();
208 // first call after the editctrl has been set
210 GetEditorCtrl()->Show();
211 GetDescWin()->Show();
213 GetEditorCtrl()->DisplayData(0);
216 void OTableDesignView::resizeDocumentView(Rectangle
& _rPlayground
)
218 m_pWin
->SetPosSizePixel( _rPlayground
.TopLeft(), _rPlayground
.GetSize() );
220 // just for completeness: there is no space left, we occupied it all ...
221 _rPlayground
.SetPos( _rPlayground
.BottomRight() );
222 _rPlayground
.SetSize( Size( 0, 0 ) );
225 bool OTableDesignView::PreNotify( NotifyEvent
& rNEvt
)
227 bool bHandled
= false;
228 if (rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
)
230 if( GetDescWin() && GetDescWin()->HasChildPathFocus() )
231 m_eChildFocus
= DESCRIPTION
;
232 else if ( GetEditorCtrl() && GetEditorCtrl()->HasChildPathFocus() )
233 m_eChildFocus
= EDITOR
;
235 m_eChildFocus
= NONE
;
238 return bHandled
|| ODataView::PreNotify(rNEvt
);
241 IClipboardTest
* OTableDesignView::getActiveChild() const
243 IClipboardTest
* pTest
= NULL
;
244 switch(m_eChildFocus
)
247 pTest
= GetDescWin();
250 pTest
= GetEditorCtrl();
258 bool OTableDesignView::isCopyAllowed()
260 IClipboardTest
* pTest
= getActiveChild();
261 return pTest
&& pTest
->isCopyAllowed();
264 bool OTableDesignView::isCutAllowed()
266 IClipboardTest
* pTest
= getActiveChild();
267 return pTest
&& pTest
->isCutAllowed();
270 bool OTableDesignView::isPasteAllowed()
272 IClipboardTest
* pTest
= getActiveChild();
273 return pTest
&& pTest
->isPasteAllowed();
276 void OTableDesignView::copy()
278 IClipboardTest
* pTest
= getActiveChild();
283 void OTableDesignView::cut()
285 IClipboardTest
* pTest
= getActiveChild();
290 void OTableDesignView::paste()
292 IClipboardTest
* pTest
= getActiveChild();
297 // set the view readonly or not
298 void OTableDesignView::setReadOnly(bool _bReadOnly
)
300 GetDescWin()->SetReadOnly(_bReadOnly
);
301 GetEditorCtrl()->SetReadOnly(_bReadOnly
);
304 void OTableDesignView::reSync()
306 GetEditorCtrl()->DeactivateCell();
307 ::boost::shared_ptr
<OTableRow
> pRow
= (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
308 OFieldDescription
* pFieldDescr
= pRow
? pRow
->GetActFieldDescr() : NULL
;
310 GetDescWin()->DisplayData(pFieldDescr
);
313 void OTableDesignView::GetFocus()
315 if ( GetEditorCtrl() )
316 GetEditorCtrl()->GrabFocus();
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */