Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / app / AppView.cxx
blob4c56fa87ba3f41199754cfcfa12520f0712b8c73
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 "dbu_app.hrc"
22 #include <tools/debug.hxx>
23 #include <tools/diagnose_ex.h>
24 #include "dbaccess_helpid.hrc"
25 #include <vcl/toolbox.hxx>
26 #include <unotools/configmgr.hxx>
27 #include <vcl/waitobj.hxx>
28 #include <comphelper/types.hxx>
29 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
32 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
33 #include <unotools/syslocale.hxx>
34 #include "UITools.hxx"
35 #include "AppDetailView.hxx"
36 #include "tabletree.hxx"
37 #include "AppSwapWindow.hxx"
38 #include <vcl/svapp.hxx>
39 #include <vcl/settings.hxx>
40 #include "AppTitleWindow.hxx"
41 #include "dsntypes.hxx"
42 #include "dbustrings.hrc"
43 #include <dbaccess/IController.hxx>
44 #include "browserids.hxx"
45 #include <unotools/pathoptions.hxx>
46 #include "IApplicationController.hxx"
47 #include <boost/scoped_ptr.hpp>
49 using namespace ::dbaui;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::ucb;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::sdb;
54 using namespace ::com::sun::star::sdbc;
55 using namespace ::com::sun::star::sdbcx;
56 using namespace ::com::sun::star::datatransfer::clipboard;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::frame;
59 using namespace ::com::sun::star::container;
60 using ::com::sun::star::sdb::application::NamedDatabaseObject;
62 // class OAppBorderWindow
63 OAppBorderWindow::OAppBorderWindow(OApplicationView* _pParent,PreviewMode _ePreviewMode) : Window(_pParent,WB_DIALOGCONTROL)
64 ,m_pPanel(NULL)
65 ,m_pDetailView(NULL)
66 ,m_pView(_pParent)
69 SetBorderStyle(WindowBorderStyle::MONO);
71 m_pPanel = VclPtr<OTitleWindow>::Create(this,STR_DATABASE,WB_BORDER | WB_DIALOGCONTROL, false);
72 m_pPanel->SetBorderStyle(WindowBorderStyle::MONO);
73 VclPtrInstance<OApplicationSwapWindow> pSwap( m_pPanel, *this );
74 pSwap->Show();
75 pSwap->SetUniqueId(UID_APP_SWAP_VIEW);
77 m_pPanel->setChildWindow(pSwap);
78 m_pPanel->SetUniqueId(UID_APP_DATABASE_VIEW);
79 m_pPanel->Show();
81 m_pDetailView = VclPtr<OApplicationDetailView>::Create(*this,_ePreviewMode);
82 m_pDetailView->Show();
84 ImplInitSettings();
87 OAppBorderWindow::~OAppBorderWindow()
89 disposeOnce();
92 void OAppBorderWindow::dispose()
94 // destroy children
95 if ( m_pPanel )
96 m_pPanel->Hide();
97 m_pPanel.disposeAndClear();
98 if ( m_pDetailView )
99 m_pDetailView->Hide();
100 m_pDetailView.disposeAndClear();
101 m_pView.clear();
102 vcl::Window::dispose();
105 void OAppBorderWindow::GetFocus()
107 if ( m_pPanel )
108 m_pPanel->GrabFocus();
111 void OAppBorderWindow::Resize()
113 // parent window dimension
114 Size aOutputSize( GetOutputSize() );
115 long nOutputWidth = aOutputSize.Width();
116 long nOutputHeight = aOutputSize.Height();
117 long nX = 0;
119 Size aFLSize = LogicToPixel( Size( 3, 8 ), MAP_APPFONT );
120 if ( m_pPanel )
122 OApplicationSwapWindow* pSwap = getPanel();
123 if ( pSwap )
125 if ( pSwap->GetEntryCount() != 0 )
126 nX = pSwap->GetBoundingBox( pSwap->GetEntry(0) ).GetWidth() + aFLSize.Height();
128 nX = ::std::max(m_pPanel->GetWidthPixel() ,nX);
129 m_pPanel->SetPosSizePixel(Point(0,0),Size(nX,nOutputHeight));
132 if ( m_pDetailView )
133 m_pDetailView->SetPosSizePixel(Point(nX + aFLSize.Width(),0),Size(nOutputWidth - nX - aFLSize.Width(),nOutputHeight));
136 void OAppBorderWindow::DataChanged( const DataChangedEvent& rDCEvt )
138 Window::DataChanged( rDCEvt );
140 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
141 (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
142 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
143 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
144 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
146 ImplInitSettings();
147 Invalidate();
151 void OAppBorderWindow::ImplInitSettings()
153 // FIXME RenderContext
154 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
155 if( true )
157 vcl::Font aFont;
158 aFont = rStyleSettings.GetFieldFont();
159 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
160 SetPointFont(*this, aFont);
163 if( true )
165 SetTextColor( rStyleSettings.GetFieldTextColor() );
166 SetTextFillColor();
169 if( true )
170 SetBackground( rStyleSettings.GetDialogColor() );
174 OApplicationSwapWindow* OAppBorderWindow::getPanel() const
176 return static_cast< OApplicationSwapWindow* >( m_pPanel->getChildWindow() );
180 // class OApplicationView
181 OApplicationView::OApplicationView( vcl::Window* pParent
182 ,const Reference< XComponentContext >& _rxOrb
183 ,IApplicationController& _rAppController
184 ,PreviewMode _ePreviewMode
186 ODataView( pParent, _rAppController, _rxOrb, WB_DIALOGCONTROL )
187 ,m_rAppController( _rAppController )
188 ,m_eChildFocus(NONE)
193 m_aLocale = SvtSysLocale().GetLanguageTag().getLocale();
195 catch(Exception&)
199 m_pWin = VclPtr<OAppBorderWindow>::Create(this,_ePreviewMode);
200 m_pWin->SetUniqueId(UID_APP_VIEW_BORDER_WIN);
201 m_pWin->Show();
203 ImplInitSettings();
206 OApplicationView::~OApplicationView()
208 disposeOnce();
211 void OApplicationView::dispose()
213 stopComponentListening(m_xObject);
214 m_xObject.clear();
215 m_pWin->Hide();
216 m_pWin.disposeAndClear();
217 ODataView::dispose();
220 void OApplicationView::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
222 if ( m_pWin && m_pWin->getPanel() )
223 m_pWin->getPanel()->createIconAutoMnemonics( _rMnemonics );
226 void OApplicationView::setTaskExternalMnemonics( MnemonicGenerator& _rMnemonics )
228 if ( m_pWin && m_pWin->getDetailView() )
229 m_pWin->getDetailView()->setTaskExternalMnemonics( _rMnemonics );
232 void OApplicationView::DataChanged( const DataChangedEvent& rDCEvt )
234 ODataView::DataChanged( rDCEvt );
236 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
237 (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
238 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
239 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
240 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
242 ImplInitSettings();
243 Invalidate();
247 void OApplicationView::resizeDocumentView(Rectangle& _rPlayground)
249 if ( m_pWin && !_rPlayground.IsEmpty() )
251 Size aFLSize = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
252 _rPlayground.Move( aFLSize.A(),aFLSize.B() );
253 Size aOldSize = _rPlayground.GetSize();
254 _rPlayground.SetSize( Size(aOldSize.A() - 2*aFLSize.A(), aOldSize.B() - 2*aFLSize.B()) );
256 m_pWin->SetPosSizePixel(_rPlayground.TopLeft() , _rPlayground.GetSize() );
258 // just for completeness: there is no space left, we occupied it all ...
259 _rPlayground.SetPos( _rPlayground.BottomRight() );
260 _rPlayground.SetSize( Size( 0, 0 ) );
263 bool OApplicationView::PreNotify( NotifyEvent& rNEvt )
265 switch(rNEvt.GetType())
267 case MouseNotifyEvent::GETFOCUS:
268 if( m_pWin && getPanel() && getPanel()->HasChildPathFocus() )
269 m_eChildFocus = PANELSWAP;
270 else if ( m_pWin && getDetailView() && getDetailView()->HasChildPathFocus() )
271 m_eChildFocus = DETAIL;
272 else
273 m_eChildFocus = NONE;
274 break;
275 case MouseNotifyEvent::KEYINPUT:
277 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
278 // give the pane the chance to intercept mnemonic accelerators
279 // #i34790#
280 if ( getPanel() && getPanel()->interceptKeyInput( *pKeyEvent ) )
281 return true;
282 // and ditto the detail view
283 // #i72799#
284 if ( getDetailView() && getDetailView()->interceptKeyInput( *pKeyEvent ) )
285 return true;
287 break;
288 default:
289 break;
292 return ODataView::PreNotify(rNEvt);
295 IClipboardTest* OApplicationView::getActiveChild() const
297 IClipboardTest* pTest = NULL;
298 if ( DETAIL == m_eChildFocus )
299 pTest = getDetailView();
300 return pTest;
303 bool OApplicationView::isCopyAllowed()
305 IClipboardTest* pTest = getActiveChild();
306 return pTest && pTest->isCopyAllowed();
309 bool OApplicationView::isCutAllowed()
311 IClipboardTest* pTest = getActiveChild();
312 return pTest && pTest->isCutAllowed();
315 bool OApplicationView::isPasteAllowed()
317 IClipboardTest* pTest = getActiveChild();
318 return pTest && pTest->isPasteAllowed();
321 void OApplicationView::copy()
323 IClipboardTest* pTest = getActiveChild();
324 if ( pTest )
325 pTest->copy();
328 void OApplicationView::cut()
330 IClipboardTest* pTest = getActiveChild();
331 if ( pTest )
332 pTest->cut();
335 void OApplicationView::paste()
337 IClipboardTest* pTest = getActiveChild();
338 if ( pTest )
339 pTest->paste();
342 OUString OApplicationView::getQualifiedName( SvTreeListEntry* _pEntry ) const
344 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
345 return getDetailView()->getQualifiedName( _pEntry );
348 bool OApplicationView::isLeaf(SvTreeListEntry* _pEntry) const
350 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
351 return OApplicationDetailView::isLeaf(_pEntry);
354 bool OApplicationView::isALeafSelected() const
356 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
357 return getDetailView()->isALeafSelected();
360 void OApplicationView::selectAll()
362 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
363 getDetailView()->selectAll();
366 bool OApplicationView::isSortUp() const
368 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
369 return getDetailView()->isSortUp();
372 void OApplicationView::sortDown()
374 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
375 getDetailView()->sortDown();
378 void OApplicationView::sortUp()
380 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
381 getDetailView()->sortUp();
384 bool OApplicationView::isFilled() const
386 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
387 return getDetailView()->isFilled();
390 ElementType OApplicationView::getElementType() const
392 OSL_ENSURE(m_pWin && getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
393 return getDetailView()->HasChildPathFocus() ? getDetailView()->getElementType() : getPanel()->getElementType();
396 sal_Int32 OApplicationView::getSelectionCount()
398 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
399 return getDetailView()->getSelectionCount();
402 sal_Int32 OApplicationView::getElementCount()
404 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
405 return getDetailView()->getElementCount();
408 void OApplicationView::getSelectionElementNames( ::std::vector< OUString>& _rNames ) const
410 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
411 getDetailView()->getSelectionElementNames( _rNames );
414 void OApplicationView::describeCurrentSelectionForControl( const Control& _rControl, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
416 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
417 getDetailView()->describeCurrentSelectionForControl( _rControl, _out_rSelectedObjects );
420 void OApplicationView::describeCurrentSelectionForType( const ElementType _eType, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
422 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
423 getDetailView()->describeCurrentSelectionForType( _eType, _out_rSelectedObjects );
426 void OApplicationView::selectElements(const Sequence< OUString>& _aNames)
428 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
429 getDetailView()->selectElements( _aNames );
432 SvTreeListEntry* OApplicationView::elementAdded(ElementType eType,const OUString& _rName, const Any& _rObject )
434 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
435 return getDetailView()->elementAdded(eType,_rName,_rObject);
438 void OApplicationView::elementRemoved(ElementType eType,const OUString& _rName )
440 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
441 getDetailView()->elementRemoved(eType,_rName);
444 void OApplicationView::elementReplaced(ElementType _eType
445 ,const OUString& _rOldName
446 ,const OUString& _rNewName )
448 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
449 getDetailView()->elementReplaced(_eType, _rOldName, _rNewName );
452 void OApplicationView::clearPages(bool _bTaskAlso)
454 OSL_ENSURE(m_pWin && getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
455 getPanel()->clearSelection();
456 getDetailView()->clearPages(_bTaskAlso);
459 void OApplicationView::selectContainer(ElementType _eType)
461 OSL_ENSURE(m_pWin && getPanel(),"Detail view is NULL! -> GPF");
462 WaitObject aWO(this);
463 getPanel()->selectContainer(_eType);
466 SvTreeListEntry* OApplicationView::getEntry( const Point& _aPosPixel ) const
468 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
469 return getDetailView()->getEntry(_aPosPixel);
472 PreviewMode OApplicationView::getPreviewMode()
474 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
475 return getDetailView()->getPreviewMode();
478 bool OApplicationView::isPreviewEnabled()
480 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
481 return getDetailView()->isPreviewEnabled();
484 void OApplicationView::switchPreview(PreviewMode _eMode)
486 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
487 getDetailView()->switchPreview(_eMode);
490 void OApplicationView::showPreview(const Reference< XContent >& _xContent)
492 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
493 stopComponentListening(m_xObject);
494 m_xObject = NULL;
495 getDetailView()->showPreview(_xContent);
498 void OApplicationView::showPreview( const OUString& _sDataSourceName,
499 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
500 const OUString& _sName,
501 bool _bTable)
503 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
504 if ( isPreviewEnabled() )
506 stopComponentListening(m_xObject);
507 m_xObject = NULL;
510 Reference<XNameAccess> xNameAccess;
511 if ( _bTable )
513 Reference<XTablesSupplier> xSup(_xConnection,UNO_QUERY);
514 if ( xSup.is() )
515 xNameAccess.set(xSup->getTables(),UNO_QUERY);
517 else
519 Reference<XQueriesSupplier> xSup(_xConnection,UNO_QUERY);
520 if ( xSup.is() )
521 xNameAccess.set(xSup->getQueries(),UNO_QUERY);
523 if ( xNameAccess.is() && xNameAccess->hasByName(_sName) )
524 m_xObject.set(xNameAccess->getByName(_sName),UNO_QUERY);
526 catch( const Exception& )
528 DBG_UNHANDLED_EXCEPTION();
530 if ( m_xObject.is() )
531 startComponentListening(m_xObject);
532 getDetailView()->showPreview(_sDataSourceName,_sName,_bTable);
536 void OApplicationView::GetFocus()
538 if ( m_eChildFocus == NONE && m_pWin )
540 m_pWin->GrabFocus();
544 void OApplicationView::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
546 if ( m_pWin && getDetailView() )
547 showPreview(NULL);
550 void OApplicationView::ImplInitSettings()
552 // FIXME RenderContext
553 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
554 if( true )
556 vcl::Font aFont;
557 aFont = rStyleSettings.GetFieldFont();
558 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
559 SetPointFont(*this, aFont);
562 if( true )
564 SetTextColor( rStyleSettings.GetFieldTextColor() );
565 SetTextFillColor();
568 if( true )
569 SetBackground( rStyleSettings.GetFieldColor() );
572 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */