1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "AppView.hxx"
30 #include "dbu_app.hrc"
31 #include <tools/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 #include "dbaccess_helpid.hrc"
34 #include <vcl/toolbox.hxx>
35 #include <unotools/configmgr.hxx>
36 #include <vcl/waitobj.hxx>
37 #include <comphelper/types.hxx>
38 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
41 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
42 #include <unotools/syslocale.hxx>
43 #include "UITools.hxx"
44 #include "AppDetailView.hxx"
45 #include "tabletree.hxx"
46 #include "AppSwapWindow.hxx"
47 #include <vcl/svapp.hxx>
48 #include "AppTitleWindow.hxx"
49 #include "dsntypes.hxx"
50 #include "dbustrings.hrc"
51 #include "IController.hxx"
52 #include "browserids.hxx"
53 #include <unotools/pathoptions.hxx>
54 #include "IApplicationController.hxx"
56 using namespace ::dbaui
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::ucb
;
59 using namespace ::com::sun::star::beans
;
60 using namespace ::com::sun::star::sdb
;
61 using namespace ::com::sun::star::sdbc
;
62 using namespace ::com::sun::star::sdbcx
;
63 using namespace ::com::sun::star::datatransfer::clipboard
;
64 using namespace ::com::sun::star::lang
;
65 using namespace ::com::sun::star::beans
;
66 using namespace ::com::sun::star::frame
;
67 using namespace ::com::sun::star::container
;
68 using ::com::sun::star::sdb::application::NamedDatabaseObject
;
70 //==================================================================
71 // class OAppBorderWindow
72 DBG_NAME(OAppBorderWindow
)
73 //==================================================================
74 OAppBorderWindow::OAppBorderWindow(OApplicationView
* _pParent
,PreviewMode _ePreviewMode
) : Window(_pParent
,WB_DIALOGCONTROL
)
79 DBG_CTOR(OAppBorderWindow
,NULL
);
81 SetBorderStyle(WINDOW_BORDER_MONO
);
83 m_pPanel
= new OTitleWindow(this,STR_DATABASE
,WB_BORDER
| WB_DIALOGCONTROL
,sal_False
);
84 m_pPanel
->SetBorderStyle(WINDOW_BORDER_MONO
);
85 OApplicationSwapWindow
* pSwap
= new OApplicationSwapWindow( m_pPanel
, *this );
87 pSwap
->SetUniqueId(UID_APP_SWAP_VIEW
);
89 m_pPanel
->setChildWindow(pSwap
);
90 m_pPanel
->SetUniqueId(UID_APP_DATABASE_VIEW
);
93 m_pDetailView
= new OApplicationDetailView(*this,_ePreviewMode
);
94 m_pDetailView
->Show();
98 // -----------------------------------------------------------------------------
99 OAppBorderWindow::~OAppBorderWindow()
105 SAL_WNODEPRECATED_DECLARATIONS_PUSH
106 ::std::auto_ptr
<Window
> aTemp(m_pPanel
);
107 SAL_WNODEPRECATED_DECLARATIONS_POP
112 m_pDetailView
->Hide();
113 SAL_WNODEPRECATED_DECLARATIONS_PUSH
114 ::std::auto_ptr
<Window
> aTemp(m_pDetailView
);
115 SAL_WNODEPRECATED_DECLARATIONS_POP
116 m_pDetailView
= NULL
;
119 DBG_DTOR(OAppBorderWindow
,NULL
);
121 // -----------------------------------------------------------------------------
122 void OAppBorderWindow::GetFocus()
125 m_pPanel
->GrabFocus();
127 // -----------------------------------------------------------------------------
128 void OAppBorderWindow::Resize()
130 // parent window dimension
131 Size
aOutputSize( GetOutputSize() );
132 long nOutputWidth
= aOutputSize
.Width();
133 long nOutputHeight
= aOutputSize
.Height();
136 Size aFLSize
= LogicToPixel( Size( 3, 8 ), MAP_APPFONT
);
139 OApplicationSwapWindow
* pSwap
= getPanel();
142 if ( pSwap
->GetEntryCount() != 0 )
143 nX
= pSwap
->GetBoundingBox( pSwap
->GetEntry(0) ).GetWidth() + aFLSize
.Height();
145 nX
= ::std::max(m_pPanel
->GetWidthPixel() ,nX
);
146 m_pPanel
->SetPosSizePixel(Point(0,0),Size(nX
,nOutputHeight
));
150 m_pDetailView
->SetPosSizePixel(Point(nX
+ aFLSize
.Width(),0),Size(nOutputWidth
- nX
- aFLSize
.Width(),nOutputHeight
));
152 // -----------------------------------------------------------------------------
153 void OAppBorderWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
155 Window::DataChanged( rDCEvt
);
157 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
158 (rDCEvt
.GetType() == DATACHANGED_DISPLAY
) ||
159 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
160 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
161 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
167 // -----------------------------------------------------------------------------
168 void OAppBorderWindow::ImplInitSettings()
170 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
174 aFont
= rStyleSettings
.GetFieldFont();
175 aFont
.SetColor( rStyleSettings
.GetWindowTextColor() );
176 SetPointFont( aFont
);
181 SetTextColor( rStyleSettings
.GetFieldTextColor() );
186 SetBackground( rStyleSettings
.GetDialogColor() );
188 // -----------------------------------------------------------------------------
189 OApplicationView
* OAppBorderWindow::getView() const
194 // -----------------------------------------------------------------------------
195 OApplicationSwapWindow
* OAppBorderWindow::getPanel() const
197 return static_cast< OApplicationSwapWindow
* >( m_pPanel
->getChildWindow() );
200 // -----------------------------------------------------------------------------
201 OApplicationDetailView
* OAppBorderWindow::getDetailView() const
203 return m_pDetailView
;
206 //==================================================================
207 // class OApplicationView
208 //==================================================================
209 DBG_NAME(OApplicationView
);
210 //------------------------------------------------------------------------------
211 OApplicationView::OApplicationView( Window
* pParent
212 ,const Reference
< XMultiServiceFactory
>& _rxOrb
213 ,IApplicationController
& _rAppController
214 ,PreviewMode _ePreviewMode
216 ODataView( pParent
, _rAppController
, _rxOrb
, WB_DIALOGCONTROL
)
217 ,m_rAppController( _rAppController
)
220 DBG_CTOR(OApplicationView
,NULL
);
224 m_aLocale
= SvtSysLocale().GetLocaleData().getLocale();
230 m_pWin
= new OAppBorderWindow(this,_ePreviewMode
);
231 m_pWin
->SetUniqueId(UID_APP_VIEW_BORDER_WIN
);
237 //------------------------------------------------------------------------------
238 OApplicationView::~OApplicationView()
240 DBG_DTOR(OApplicationView
,NULL
);
243 stopComponentListening(m_xObject
);
245 SAL_WNODEPRECATED_DECLARATIONS_PUSH
246 ::std::auto_ptr
<Window
> aTemp(m_pWin
);
247 SAL_WNODEPRECATED_DECLARATIONS_POP
251 // -----------------------------------------------------------------------------
252 void OApplicationView::createIconAutoMnemonics( MnemonicGenerator
& _rMnemonics
)
254 if ( m_pWin
&& m_pWin
->getPanel() )
255 m_pWin
->getPanel()->createIconAutoMnemonics( _rMnemonics
);
258 // -----------------------------------------------------------------------------
259 void OApplicationView::setTaskExternalMnemonics( MnemonicGenerator
& _rMnemonics
)
261 if ( m_pWin
&& m_pWin
->getDetailView() )
262 m_pWin
->getDetailView()->setTaskExternalMnemonics( _rMnemonics
);
265 // -----------------------------------------------------------------------------
266 void OApplicationView::DataChanged( const DataChangedEvent
& rDCEvt
)
268 ODataView::DataChanged( rDCEvt
);
270 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
271 (rDCEvt
.GetType() == DATACHANGED_DISPLAY
) ||
272 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
273 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
274 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
280 //------------------------------------------------------------------------------
281 void OApplicationView::resizeDocumentView(Rectangle
& _rPlayground
)
283 if ( m_pWin
&& !_rPlayground
.IsEmpty() )
285 Size aFLSize
= LogicToPixel( Size( 3, 3 ), MAP_APPFONT
);
286 _rPlayground
.Move( aFLSize
.A(),aFLSize
.B() );
287 Size aOldSize
= _rPlayground
.GetSize();
288 _rPlayground
.SetSize( Size(aOldSize
.A() - 2*aFLSize
.A(), aOldSize
.B() - 2*aFLSize
.B()) );
290 m_pWin
->SetPosSizePixel(_rPlayground
.TopLeft() , _rPlayground
.GetSize() );
292 // just for completeness: there is no space left, we occupied it all ...
293 _rPlayground
.SetPos( _rPlayground
.BottomRight() );
294 _rPlayground
.SetSize( Size( 0, 0 ) );
296 //------------------------------------------------------------------------------
297 long OApplicationView::PreNotify( NotifyEvent
& rNEvt
)
299 switch(rNEvt
.GetType())
302 if( m_pWin
&& getPanel() && getPanel()->HasChildPathFocus() )
303 m_eChildFocus
= PANELSWAP
;
304 else if ( m_pWin
&& getDetailView() && getDetailView()->HasChildPathFocus() )
305 m_eChildFocus
= DETAIL
;
307 m_eChildFocus
= NONE
;
311 const KeyEvent
* pKeyEvent
= rNEvt
.GetKeyEvent();
312 // give the pane the chance to intercept mnemonic accelerators
314 if ( getPanel() && getPanel()->interceptKeyInput( *pKeyEvent
) )
316 // and ditto the detail view
318 if ( getDetailView() && getDetailView()->interceptKeyInput( *pKeyEvent
) )
324 return ODataView::PreNotify(rNEvt
);
326 // -----------------------------------------------------------------------------
327 IClipboardTest
* OApplicationView::getActiveChild() const
329 IClipboardTest
* pTest
= NULL
;
330 if ( DETAIL
== m_eChildFocus
)
331 pTest
= getDetailView();
334 // -----------------------------------------------------------------------------
335 sal_Bool
OApplicationView::isCopyAllowed()
337 IClipboardTest
* pTest
= getActiveChild();
338 return pTest
&& pTest
->isCopyAllowed();
340 // -----------------------------------------------------------------------------
341 sal_Bool
OApplicationView::isCutAllowed()
343 IClipboardTest
* pTest
= getActiveChild();
344 return pTest
&& pTest
->isCutAllowed();
346 // -----------------------------------------------------------------------------
347 sal_Bool
OApplicationView::isPasteAllowed()
349 IClipboardTest
* pTest
= getActiveChild();
350 return pTest
&& pTest
->isPasteAllowed();
352 // -----------------------------------------------------------------------------
353 void OApplicationView::copy()
355 IClipboardTest
* pTest
= getActiveChild();
359 // -----------------------------------------------------------------------------
360 void OApplicationView::cut()
362 IClipboardTest
* pTest
= getActiveChild();
366 // -----------------------------------------------------------------------------
367 void OApplicationView::paste()
369 IClipboardTest
* pTest
= getActiveChild();
373 // -----------------------------------------------------------------------------
374 ::rtl::OUString
OApplicationView::getQualifiedName( SvLBoxEntry
* _pEntry
) const
376 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
377 return getDetailView()->getQualifiedName( _pEntry
);
379 // -----------------------------------------------------------------------------
380 sal_Bool
OApplicationView::isLeaf(SvLBoxEntry
* _pEntry
) const
382 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
383 return getDetailView()->isLeaf(_pEntry
);
385 // -----------------------------------------------------------------------------
386 sal_Bool
OApplicationView::isALeafSelected() const
388 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
389 return getDetailView()->isALeafSelected();
391 // -----------------------------------------------------------------------------
392 void OApplicationView::selectAll()
394 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
395 getDetailView()->selectAll();
397 // -----------------------------------------------------------------------------
398 sal_Bool
OApplicationView::isSortUp() const
400 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
401 return getDetailView()->isSortUp();
403 // -----------------------------------------------------------------------------
404 void OApplicationView::sortDown()
406 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
407 getDetailView()->sortDown();
409 // -----------------------------------------------------------------------------
410 void OApplicationView::sortUp()
412 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
413 getDetailView()->sortUp();
415 // -----------------------------------------------------------------------------
416 sal_Bool
OApplicationView::isFilled() const
418 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
419 return getDetailView()->isFilled();
421 // -----------------------------------------------------------------------------
422 ElementType
OApplicationView::getElementType() const
424 OSL_ENSURE(m_pWin
&& getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
425 return getDetailView()->HasChildPathFocus() ? getDetailView()->getElementType() : getPanel()->getElementType();
427 // -----------------------------------------------------------------------------
428 sal_Int32
OApplicationView::getSelectionCount()
430 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
431 return getDetailView()->getSelectionCount();
433 // -----------------------------------------------------------------------------
434 sal_Int32
OApplicationView::getElementCount()
436 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
437 return getDetailView()->getElementCount();
439 // -----------------------------------------------------------------------------
440 void OApplicationView::getSelectionElementNames( ::std::vector
< ::rtl::OUString
>& _rNames
) const
442 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
443 getDetailView()->getSelectionElementNames( _rNames
);
445 // -----------------------------------------------------------------------------
446 void OApplicationView::describeCurrentSelectionForControl( const Control
& _rControl
, Sequence
< NamedDatabaseObject
>& _out_rSelectedObjects
)
448 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
449 getDetailView()->describeCurrentSelectionForControl( _rControl
, _out_rSelectedObjects
);
451 // -----------------------------------------------------------------------------
452 void OApplicationView::describeCurrentSelectionForType( const ElementType _eType
, Sequence
< NamedDatabaseObject
>& _out_rSelectedObjects
)
454 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
455 getDetailView()->describeCurrentSelectionForType( _eType
, _out_rSelectedObjects
);
457 // -----------------------------------------------------------------------------
458 void OApplicationView::selectElements(const Sequence
< ::rtl::OUString
>& _aNames
)
460 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
461 getDetailView()->selectElements( _aNames
);
463 // -----------------------------------------------------------------------------
464 SvLBoxEntry
* OApplicationView::elementAdded(ElementType eType
,const ::rtl::OUString
& _rName
, const Any
& _rObject
)
466 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
467 return getDetailView()->elementAdded(eType
,_rName
,_rObject
);
469 // -----------------------------------------------------------------------------
470 void OApplicationView::elementRemoved(ElementType eType
,const ::rtl::OUString
& _rName
)
472 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
473 getDetailView()->elementRemoved(eType
,_rName
);
475 // -----------------------------------------------------------------------------
476 void OApplicationView::elementReplaced(ElementType _eType
477 ,const ::rtl::OUString
& _rOldName
478 ,const ::rtl::OUString
& _rNewName
)
480 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
481 getDetailView()->elementReplaced(_eType
, _rOldName
, _rNewName
);
483 // -----------------------------------------------------------------------------
484 void OApplicationView::clearPages(sal_Bool _bTaskAlso
)
486 OSL_ENSURE(m_pWin
&& getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
487 getPanel()->clearSelection();
488 getDetailView()->clearPages(_bTaskAlso
);
490 // -----------------------------------------------------------------------------
491 void OApplicationView::selectContainer(ElementType _eType
)
493 OSL_ENSURE(m_pWin
&& getPanel(),"Detail view is NULL! -> GPF");
494 WaitObject
aWO(this);
495 getPanel()->selectContainer(_eType
);
497 // -----------------------------------------------------------------------------
498 SvLBoxEntry
* OApplicationView::getEntry( const Point
& _aPosPixel
) const
500 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
501 return getDetailView()->getEntry(_aPosPixel
);
503 // -----------------------------------------------------------------------------
504 PreviewMode
OApplicationView::getPreviewMode()
506 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
507 return getDetailView()->getPreviewMode();
509 // -----------------------------------------------------------------------------
510 sal_Bool
OApplicationView::isPreviewEnabled()
512 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
513 return getDetailView()->isPreviewEnabled();
515 // -----------------------------------------------------------------------------
516 void OApplicationView::switchPreview(PreviewMode _eMode
)
518 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
519 getDetailView()->switchPreview(_eMode
);
521 // -----------------------------------------------------------------------------
522 void OApplicationView::showPreview(const Reference
< XContent
>& _xContent
)
524 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
525 stopComponentListening(m_xObject
);
527 getDetailView()->showPreview(_xContent
);
529 // -----------------------------------------------------------------------------
530 void OApplicationView::showPreview( const ::rtl::OUString
& _sDataSourceName
,
531 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,
532 const ::rtl::OUString
& _sName
,
535 OSL_ENSURE(m_pWin
&& getDetailView(),"Detail view is NULL! -> GPF");
536 if ( isPreviewEnabled() )
538 stopComponentListening(m_xObject
);
542 Reference
<XNameAccess
> xNameAccess
;
545 Reference
<XTablesSupplier
> xSup(_xConnection
,UNO_QUERY
);
547 xNameAccess
.set(xSup
->getTables(),UNO_QUERY
);
551 Reference
<XQueriesSupplier
> xSup(_xConnection
,UNO_QUERY
);
553 xNameAccess
.set(xSup
->getQueries(),UNO_QUERY
);
555 if ( xNameAccess
.is() && xNameAccess
->hasByName(_sName
) )
556 m_xObject
.set(xNameAccess
->getByName(_sName
),UNO_QUERY
);
558 catch( const Exception
& )
560 DBG_UNHANDLED_EXCEPTION();
562 if ( m_xObject
.is() )
563 startComponentListening(m_xObject
);
564 getDetailView()->showPreview(_sDataSourceName
,_sName
,_bTable
);
567 // -----------------------------------------------------------------------------
568 void OApplicationView::GetFocus()
570 if ( m_eChildFocus
== NONE
&& m_pWin
)
575 // -----------------------------------------------------------------------------
576 void OApplicationView::_disposing( const ::com::sun::star::lang::EventObject
& /*_rSource*/ )
578 if ( m_pWin
&& getDetailView() )
581 // -----------------------------------------------------------------------------
582 void OApplicationView::ImplInitSettings()
584 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
588 aFont
= rStyleSettings
.GetFieldFont();
589 aFont
.SetColor( rStyleSettings
.GetWindowTextColor() );
590 SetPointFont( aFont
);
595 SetTextColor( rStyleSettings
.GetFieldTextColor() );
600 SetBackground( rStyleSettings
.GetFieldColor() );
602 //-----------------------------------------------------------------------------
604 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */