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 <TableController.hxx>
23 #include <FieldDescriptions.hxx>
24 #include "TEditControl.hxx"
25 #include "TableFieldDescWin.hxx"
26 #include <TableRow.hxx>
27 #include <i18nlangtag/languagetag.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <unotools/syslocale.hxx>
32 using namespace ::dbaui
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::datatransfer::clipboard
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::beans
;
38 OTableBorderWindow::OTableBorderWindow(OTableDesignView
* pParent
)
39 : InterimItemWindow(pParent
, "dbaccess/ui/tableborderwindow.ui", "TableBorderWindow", false)
40 , m_xHorzSplitter(m_xBuilder
->weld_paned("splitter"))
41 , m_xEditorParent(m_xBuilder
->weld_container("editor"))
42 , m_xEditorParentWin(m_xEditorParent
->CreateChildFrame())
43 , m_xEditorCtrl(VclPtr
<OTableEditorCtrl
>::Create(VCLUnoHelper::GetWindow(m_xEditorParentWin
), pParent
))
44 , m_xFieldDescParent(m_xBuilder
->weld_container("fielddesc"))
45 , m_xFieldDescWin(new OTableFieldDescWin(m_xFieldDescParent
.get(), pParent
))
47 SetStyle(GetStyle() | WB_DIALOGCONTROL
);
49 m_xFieldDescWin
->SetHelpId(HID_TAB_DESIGN_DESCWIN
);
51 // set depending windows and controls
52 m_xEditorCtrl
->SetDescrWin(m_xFieldDescWin
.get());
55 OTableBorderWindow::~OTableBorderWindow()
60 void OTableBorderWindow::dispose()
63 m_xEditorCtrl
.disposeAndClear();
64 m_xEditorParentWin
->dispose();
65 m_xEditorParentWin
.clear();
66 m_xEditorParent
.reset();
67 m_xFieldDescWin
.reset();
68 m_xFieldDescParent
.reset();
69 m_xHorzSplitter
.reset();
70 InterimItemWindow::dispose();
73 void OTableBorderWindow::Layout()
75 // dimensions of parent window
76 auto nOutputHeight
= GetSizePixel().Height();
77 auto nOldSplitPos
= m_xHorzSplitter
->get_position();
78 auto nSplitPos
= nOldSplitPos
;
80 // shift range of the splitter is the middle third of the output
81 auto nDragPosY
= nOutputHeight
/3;
82 auto nDragSizeHeight
= nOutputHeight
/3;
83 if (nSplitPos
< nDragPosY
|| nSplitPos
> nDragPosY
+ nDragSizeHeight
)
84 nSplitPos
= nDragPosY
+ nDragSizeHeight
;
87 m_xHorzSplitter
->set_position(nSplitPos
);
89 InterimItemWindow::Layout();
91 if (nOldSplitPos
!= nSplitPos
)
92 m_xHorzSplitter
->set_position(nSplitPos
);
95 void OTableBorderWindow::GetFocus()
97 InterimItemWindow::GetFocus();
99 // forward the focus to the current cell of the editor control
101 m_xEditorCtrl
->GrabFocus();
104 OTableDesignView::OTableDesignView( vcl::Window
* pParent
,
105 const Reference
< XComponentContext
>& _rxOrb
,
106 OTableController
& _rController
108 ODataView( pParent
, _rController
,_rxOrb
)
109 ,m_rController( _rController
)
115 m_aLocale
= SvtSysLocale().GetLanguageTag().getLocale();
121 m_pWin
= VclPtr
<OTableBorderWindow
>::Create(this);
123 m_pWin
->GetDescWin()->connect_focus_in(LINK(this, OTableDesignView
, FieldDescFocusIn
));
128 OTableDesignView::~OTableDesignView()
133 void OTableDesignView::dispose()
136 m_pWin
.disposeAndClear();
137 ODataView::dispose();
140 void OTableDesignView::initialize()
142 GetEditorCtrl()->Init();
143 GetDescWin()->Init();
144 // first call after the editctrl has been set
146 GetEditorCtrl()->Show();
147 GetDescWin()->Show();
149 GetEditorCtrl()->DisplayData(0);
152 void OTableDesignView::resizeDocumentView(tools::Rectangle
& _rPlayground
)
154 m_pWin
->SetPosSizePixel( _rPlayground
.TopLeft(), _rPlayground
.GetSize() );
156 // just for completeness: there is no space left, we occupied it all ...
157 _rPlayground
.SetPos( _rPlayground
.BottomRight() );
158 _rPlayground
.SetSize( Size( 0, 0 ) );
161 IMPL_LINK_NOARG(OTableDesignView
, FieldDescFocusIn
, weld::Widget
&, void)
163 m_eChildFocus
= DESCRIPTION
;
166 bool OTableDesignView::PreNotify( NotifyEvent
& rNEvt
)
168 if (rNEvt
.GetType() == NotifyEventType::GETFOCUS
)
170 if( GetDescWin() && GetDescWin()->HasChildPathFocus() )
171 m_eChildFocus
= DESCRIPTION
;
172 else if ( GetEditorCtrl() && GetEditorCtrl()->HasChildPathFocus() )
173 m_eChildFocus
= EDITOR
;
175 m_eChildFocus
= NONE
;
178 return ODataView::PreNotify(rNEvt
);
181 IClipboardTest
* OTableDesignView::getActiveChild() const
183 IClipboardTest
* pTest
= nullptr;
184 switch(m_eChildFocus
)
187 pTest
= GetDescWin();
190 pTest
= GetEditorCtrl();
198 bool OTableDesignView::isCopyAllowed()
200 IClipboardTest
* pTest
= getActiveChild();
201 return pTest
&& pTest
->isCopyAllowed();
204 bool OTableDesignView::isCutAllowed()
206 IClipboardTest
* pTest
= getActiveChild();
207 return pTest
&& pTest
->isCutAllowed();
210 bool OTableDesignView::isPasteAllowed()
212 IClipboardTest
* pTest
= getActiveChild();
213 return pTest
&& pTest
->isPasteAllowed();
216 void OTableDesignView::copy()
218 IClipboardTest
* pTest
= getActiveChild();
223 void OTableDesignView::cut()
225 IClipboardTest
* pTest
= getActiveChild();
230 void OTableDesignView::paste()
232 IClipboardTest
* pTest
= getActiveChild();
237 // set the view readonly or not
238 void OTableDesignView::setReadOnly(bool _bReadOnly
)
240 GetDescWin()->SetReadOnly(_bReadOnly
);
241 GetEditorCtrl()->SetReadOnly(_bReadOnly
);
244 void OTableDesignView::reSync()
246 GetEditorCtrl()->DeactivateCell();
247 std::shared_ptr
<OTableRow
> pRow
= (*GetEditorCtrl()->GetRowList())[GetEditorCtrl()->GetCurRow()];
248 OFieldDescription
* pFieldDescr
= pRow
? pRow
->GetActFieldDescr() : nullptr;
250 GetDescWin()->DisplayData(pFieldDescr
);
253 void OTableDesignView::GetFocus()
255 if ( GetEditorCtrl() )
256 GetEditorCtrl()->GrabFocus();
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */