Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / app / AppView.cxx
blobca2e724a1bf33c55ed99246a7cf8d48d3c92c39b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "AppView.hxx"
21 #include <strings.hrc>
22 #include <comphelper/diagnose_ex.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/weld.hxx>
25 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
26 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
27 #include "AppDetailView.hxx"
28 #include "AppSwapWindow.hxx"
29 #include <vcl/settings.hxx>
30 #include "AppTitleWindow.hxx"
31 #include "AppController.hxx"
33 using namespace ::dbaui;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::ucb;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::sdb;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::sdbcx;
40 using namespace ::com::sun::star::datatransfer::clipboard;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::container;
43 using ::com::sun::star::sdb::application::NamedDatabaseObject;
45 OAppBorderWindow::OAppBorderWindow(OApplicationView* pParent, PreviewMode ePreviewMode)
46 : InterimItemWindow(pParent, u"dbaccess/ui/appborderwindow.ui"_ustr, u"AppBorderWindow"_ustr, false)
47 , m_xPanelParent(m_xBuilder->weld_container(u"panel"_ustr))
48 , m_xDetailViewParent(m_xBuilder->weld_container(u"detail"_ustr))
49 , m_xView(pParent)
51 SetStyle(GetStyle() | WB_DIALOGCONTROL);
53 m_xPanel.reset(new OTitleWindow(m_xPanelParent.get(), STR_DATABASE));
54 std::shared_ptr<OChildWindow> xSwap = std::make_shared<OApplicationSwapWindow>(m_xPanel->getChildContainer(), *this);
56 m_xPanel->setChildWindow(xSwap);
58 m_xDetailView.reset(new OApplicationDetailView(m_xDetailViewParent.get(), *this, ePreviewMode));
60 ImplInitSettings();
63 OAppBorderWindow::~OAppBorderWindow()
65 disposeOnce();
68 void OAppBorderWindow::dispose()
70 // destroy children
71 m_xPanel.reset();
72 m_xDetailView.reset();
73 m_xPanelParent.reset();
74 m_xDetailViewParent.reset();
75 m_xView.clear();
76 InterimItemWindow::dispose();
79 void OAppBorderWindow::GetFocus()
81 if (m_xPanel)
82 m_xPanel->GrabFocus();
85 OApplicationSwapWindow* OAppBorderWindow::getPanel() const
87 return static_cast<OApplicationSwapWindow*>(m_xPanel->getChildWindow());
90 OApplicationView::OApplicationView( vcl::Window* pParent
91 ,const Reference< XComponentContext >& _rxOrb
92 ,OApplicationController& _rAppController
93 ,PreviewMode _ePreviewMode
94 ) :
95 ODataView( pParent, _rAppController, _rxOrb, WB_DIALOGCONTROL )
96 ,m_rAppController( _rAppController )
98 m_pWin = VclPtr<OAppBorderWindow>::Create(this,_ePreviewMode);
99 m_pWin->Show();
101 ImplInitSettings();
104 OApplicationView::~OApplicationView()
106 disposeOnce();
109 void OApplicationView::dispose()
111 stopComponentListening(m_xObject);
112 m_xObject.clear();
113 m_pWin->Hide();
114 m_pWin.disposeAndClear();
115 ODataView::dispose();
118 void OApplicationView::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
120 if ( m_pWin && m_pWin->getPanel() )
121 m_pWin->getPanel()->createIconAutoMnemonics( _rMnemonics );
124 void OApplicationView::setTaskExternalMnemonics( MnemonicGenerator const & _rMnemonics )
126 if ( m_pWin && m_pWin->getDetailView() )
127 m_pWin->getDetailView()->setTaskExternalMnemonics( _rMnemonics );
130 void OApplicationView::DataChanged( const DataChangedEvent& rDCEvt )
132 ODataView::DataChanged( rDCEvt );
134 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
135 (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
136 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
137 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
138 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
140 ImplInitSettings();
141 Invalidate();
145 void OApplicationView::resizeDocumentView(tools::Rectangle& _rPlayground)
147 if ( m_pWin && !_rPlayground.IsEmpty() )
149 Size aFLSize = LogicToPixel(Size(3, 3), MapMode(MapUnit::MapAppFont));
150 _rPlayground.Move( aFLSize.Width(),aFLSize.Height() );
151 Size aOldSize = _rPlayground.GetSize();
152 _rPlayground.SetSize( Size(aOldSize.Width() - 2*aFLSize.Width(), aOldSize.Height() - 2*aFLSize.Height()) );
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 OApplicationView::ChildFocusState OApplicationView::getChildFocus() const
163 ChildFocusState eChildFocus;
164 if( m_pWin && getPanel() && getPanel()->HasChildPathFocus() )
165 eChildFocus = PANELSWAP;
166 else if ( m_pWin && getDetailView() && getDetailView()->HasChildPathFocus() )
167 eChildFocus = DETAIL;
168 else
169 eChildFocus = NONE;
170 return eChildFocus;
173 bool OApplicationView::PreNotify( NotifyEvent& rNEvt )
175 switch(rNEvt.GetType())
177 case NotifyEventType::KEYINPUT:
179 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
180 // give the pane the chance to intercept mnemonic accelerators
181 // #i34790#
182 if ( getPanel() && getPanel()->interceptKeyInput( *pKeyEvent ) )
183 return true;
185 break;
186 default:
187 break;
190 return ODataView::PreNotify(rNEvt);
193 IClipboardTest* OApplicationView::getActiveChild() const
195 IClipboardTest* pTest = nullptr;
196 if (getChildFocus() == DETAIL)
197 pTest = getDetailView();
198 return pTest;
201 bool OApplicationView::isCopyAllowed()
203 IClipboardTest* pTest = getActiveChild();
204 return pTest && pTest->isCopyAllowed();
207 bool OApplicationView::isCutAllowed()
209 IClipboardTest* pTest = getActiveChild();
210 return pTest && pTest->isCutAllowed();
213 bool OApplicationView::isPasteAllowed()
215 IClipboardTest* pTest = getActiveChild();
216 return pTest && pTest->isPasteAllowed();
219 void OApplicationView::copy()
221 IClipboardTest* pTest = getActiveChild();
222 if ( pTest )
223 pTest->copy();
226 void OApplicationView::cut()
228 IClipboardTest* pTest = getActiveChild();
229 if ( pTest )
230 pTest->cut();
233 void OApplicationView::paste()
235 IClipboardTest* pTest = getActiveChild();
236 if ( pTest )
237 pTest->paste();
240 OUString OApplicationView::getQualifiedName(const weld::TreeIter* _pEntry) const
242 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
243 return getDetailView()->getQualifiedName( _pEntry );
246 bool OApplicationView::isLeaf(const weld::TreeView& rTreeView, const weld::TreeIter& rEntry) const
248 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
249 return OApplicationDetailView::isLeaf(rTreeView, rEntry);
252 bool OApplicationView::isALeafSelected() const
254 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
255 return getDetailView()->isALeafSelected();
258 void OApplicationView::selectAll()
260 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
261 getDetailView()->selectAll();
264 bool OApplicationView::isSortUp() const
266 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
267 return getDetailView()->isSortUp();
270 void OApplicationView::sortDown()
272 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
273 getDetailView()->sortDown();
276 void OApplicationView::sortUp()
278 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
279 getDetailView()->sortUp();
282 bool OApplicationView::isFilled() const
284 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
285 return getDetailView()->isFilled();
288 ElementType OApplicationView::getElementType() const
290 OSL_ENSURE(m_pWin && getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
291 return getDetailView()->HasChildPathFocus() ? getDetailView()->getElementType() : getPanel()->getElementType();
294 sal_Int32 OApplicationView::getSelectionCount() const
296 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
297 return getDetailView()->getSelectionCount();
300 sal_Int32 OApplicationView::getElementCount() const
302 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
303 return getDetailView()->getElementCount();
306 void OApplicationView::getSelectionElementNames( std::vector< OUString>& _rNames ) const
308 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
309 getDetailView()->getSelectionElementNames( _rNames );
312 void OApplicationView::describeCurrentSelectionForControl(const weld::TreeView& rControl, Sequence<NamedDatabaseObject>& out_rSelectedObjects)
314 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
315 getDetailView()->describeCurrentSelectionForControl(rControl, out_rSelectedObjects);
318 vcl::Window* OApplicationView::getMenuParent() const
320 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
321 return getDetailView()->getMenuParent();
324 void OApplicationView::adjustMenuPosition(const weld::TreeView& rControl, ::Point& rPos) const
326 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
327 return getDetailView()->adjustMenuPosition(rControl, rPos);
330 void OApplicationView::describeCurrentSelectionForType( const ElementType _eType, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
332 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
333 getDetailView()->describeCurrentSelectionForType( _eType, _out_rSelectedObjects );
336 void OApplicationView::selectElements(const Sequence< OUString>& _aNames)
338 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
339 getDetailView()->selectElements( _aNames );
342 std::unique_ptr<weld::TreeIter> OApplicationView::elementAdded(ElementType eType,const OUString& _rName, const Any& _rObject )
344 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
345 return getDetailView()->elementAdded(eType,_rName,_rObject);
348 void OApplicationView::elementRemoved(ElementType eType,const OUString& _rName )
350 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
351 getDetailView()->elementRemoved(eType,_rName);
354 void OApplicationView::elementReplaced(ElementType _eType
355 ,const OUString& _rOldName
356 ,const OUString& _rNewName )
358 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
359 getDetailView()->elementReplaced(_eType, _rOldName, _rNewName );
362 void OApplicationView::clearPages()
364 OSL_ENSURE(m_pWin && getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
365 getPanel()->clearSelection();
366 getDetailView()->clearPages();
369 void OApplicationView::selectContainer(ElementType _eType)
371 OSL_ENSURE(m_pWin && getPanel(),"Detail view is NULL! -> GPF");
372 weld::WaitObject aWO(GetFrameWeld());
373 getPanel()->selectContainer(_eType);
376 std::unique_ptr<weld::TreeIter> OApplicationView::getEntry(const Point& rPosPixel) const
378 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
379 return getDetailView()->getEntry(rPosPixel);
382 PreviewMode OApplicationView::getPreviewMode() const
384 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
385 return getDetailView()->getPreviewMode();
388 bool OApplicationView::isPreviewEnabled() const
390 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
391 return getDetailView()->isPreviewEnabled();
394 void OApplicationView::switchPreview(PreviewMode _eMode)
396 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
397 getDetailView()->switchPreview(_eMode);
400 void OApplicationView::showPreview(const Reference< XContent >& _xContent)
402 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
403 stopComponentListening(m_xObject);
404 m_xObject = nullptr;
405 getDetailView()->showPreview(_xContent);
408 void OApplicationView::showPreview( const OUString& _sDataSourceName,
409 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
410 const OUString& _sName,
411 bool _bTable)
413 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
414 if ( !isPreviewEnabled() )
415 return;
417 stopComponentListening(m_xObject);
418 m_xObject = nullptr;
421 Reference<XNameAccess> xNameAccess;
422 if ( _bTable )
424 Reference<XTablesSupplier> xSup(_xConnection,UNO_QUERY);
425 if ( xSup.is() )
426 xNameAccess = xSup->getTables();
428 else
430 Reference<XQueriesSupplier> xSup(_xConnection,UNO_QUERY);
431 if ( xSup.is() )
432 xNameAccess = xSup->getQueries();
434 if ( xNameAccess.is() && xNameAccess->hasByName(_sName) )
435 m_xObject.set(xNameAccess->getByName(_sName),UNO_QUERY);
437 catch( const Exception& )
439 DBG_UNHANDLED_EXCEPTION("dbaccess");
441 if ( m_xObject.is() )
442 startComponentListening(m_xObject);
443 getDetailView()->showPreview(_sDataSourceName,_sName,_bTable);
446 void OApplicationView::GetFocus()
448 if (m_pWin && getChildFocus() == NONE)
449 m_pWin->GrabFocus();
452 void OApplicationView::_disposing( const css::lang::EventObject& /*_rSource*/ )
454 if ( m_pWin && getDetailView() )
455 showPreview(nullptr);
458 void OApplicationView::ImplInitSettings()
460 // FIXME RenderContext
461 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
463 vcl::Font aFont = rStyleSettings.GetFieldFont();
464 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
465 SetPointFont(*GetOutDev(), aFont);
467 SetTextColor( rStyleSettings.GetFieldTextColor() );
468 SetTextFillColor();
470 SetBackground( rStyleSettings.GetFieldColor() );
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */