Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / app / AppDetailPageHelper.cxx
blobe16f45f957d92509650751bc6ab14ecd10510099
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 "AppDetailPageHelper.hxx"
30 #include "moduledbu.hxx"
31 #include <tools/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <connectivity/dbtools.hxx>
34 #include "tabletree.hxx"
35 #include "UITools.hxx"
36 #include "dbtreelistbox.hxx"
37 #include <com/sun/star/frame/XLayoutManager.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/awt/XTabController.hpp>
40 #include <com/sun/star/sdbc/XConnection.hpp>
41 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
42 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
43 #include <com/sun/star/frame/XFrame.hpp>
44 #include <com/sun/star/frame/FrameSearchFlag.hpp>
45 #include <com/sun/star/frame/XComponentLoader.hpp>
46 #include <com/sun/star/frame/XFrames.hpp>
47 #include <com/sun/star/frame/XFramesSupplier.hpp>
48 #include <com/sun/star/awt/XWindow.hpp>
49 #include <toolkit/helper/vclunohelper.hxx>
50 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
51 #include <com/sun/star/ucb/XCommandProcessor.hpp>
52 #include <com/sun/star/ucb/Command.hpp>
53 #include <com/sun/star/form/XLoadable.hpp>
54 #include <com/sun/star/container/XChild.hpp>
55 #include <com/sun/star/container/XContainer.hpp>
56 #include <com/sun/star/sdb/CommandType.hpp>
57 #include <com/sun/star/util/XCloseable.hpp>
58 #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
59 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
60 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
61 #include "AppView.hxx"
62 #include "dbaccess_helpid.hrc"
63 #include "dbu_app.hrc"
64 #include "callbacks.hxx"
65 #include "IController.hxx"
66 #include "dbustrings.hrc"
67 #include "dbaccess_slotid.hrc"
68 #include "databaseobjectview.hxx"
69 #include "imageprovider.hxx"
70 #include <vcl/waitobj.hxx>
71 #include <tools/stream.hxx>
72 #include <rtl/ustrbuf.hxx>
73 #include "IApplicationController.hxx"
75 #include <com/sun/star/document/XDocumentProperties.hpp>
78 using namespace ::dbaui;
79 using namespace ::com::sun::star::container;
80 using namespace ::com::sun::star::uno;
81 using namespace ::com::sun::star::ucb;
82 using namespace ::com::sun::star::frame;
83 using namespace ::com::sun::star::form;
84 using namespace ::com::sun::star::sdb;
85 using namespace ::com::sun::star::sdb::application;
86 using namespace ::com::sun::star::sdbc;
87 using namespace ::com::sun::star::sdbcx;
88 using namespace ::com::sun::star::beans;
89 using namespace ::com::sun::star;
90 using ::com::sun::star::awt::XTabController;
92 namespace dbaui
94 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
95 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
98 namespace
100 SvLBoxEntry* lcl_findEntry_impl(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvLBoxEntry* _pFirst)
102 SvLBoxEntry* pReturn = NULL;
103 sal_Int32 nIndex = 0;
104 String sName( _rName.getToken(0,'/',nIndex) );
106 SvLBoxEntry* pEntry = _pFirst;
107 while( pEntry )
109 if ( rTree.GetEntryText(pEntry) == sName )
111 if ( nIndex != -1 )
113 sName = _rName.getToken(0,'/',nIndex);
114 pEntry = rTree.FirstChild(pEntry);
116 else
118 pReturn = pEntry;
119 break;
122 else
123 pEntry = rTree.NextSibling(pEntry);
125 return pReturn;
127 SvLBoxEntry* lcl_findEntry(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvLBoxEntry* _pFirst)
129 sal_Int32 nIndex = 0;
130 ::rtl::OUString sErase = _rName.getToken(0,'/',nIndex); // we don't want to have the "private:forms" part
131 return (nIndex != -1 ? lcl_findEntry_impl(rTree,_rName.copy(sErase.getLength() + 1),_pFirst) : NULL);
133 //==================================================================
134 // class OPreviewWindow
135 //==================================================================
136 class OTablePreviewWindow : public Window
138 DECL_LINK(OnDisableInput, void*);
139 void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
140 protected:
141 virtual void DataChanged(const DataChangedEvent& rDCEvt);
142 public:
143 OTablePreviewWindow( Window* pParent, WinBits nStyle = 0 );
144 virtual long Notify( NotifyEvent& rNEvt );
146 // -----------------------------------------------------------------------------
147 OTablePreviewWindow::OTablePreviewWindow(Window* pParent, WinBits nStyle) : Window( pParent, nStyle)
149 ImplInitSettings( sal_True, sal_True, sal_True );
151 // -----------------------------------------------------------------------------
152 long OTablePreviewWindow::Notify( NotifyEvent& rNEvt )
154 long nRet = Window::Notify( rNEvt );
155 if ( rNEvt.GetType() == EVENT_INPUTENABLE && IsInputEnabled() )
156 PostUserEvent( LINK( this, OTablePreviewWindow, OnDisableInput) );
157 return nRet;
159 // -----------------------------------------------------------------------------
160 IMPL_LINK_NOARG(OTablePreviewWindow, OnDisableInput)
162 EnableInput(sal_False);
163 return 0L;
165 // -----------------------------------------------------------------------------
166 void OTablePreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
168 Window::DataChanged( rDCEvt );
170 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
171 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
173 ImplInitSettings( sal_True, sal_True, sal_True );
174 Invalidate();
177 // -----------------------------------------------------------------------------
178 void OTablePreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
180 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
181 if( bFont )
183 Font aFont;
184 aFont = rStyleSettings.GetFieldFont();
185 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
186 SetPointFont( aFont );
189 if( bForeground || bFont )
191 SetTextColor( rStyleSettings.GetFieldTextColor() );
192 SetTextFillColor();
195 if( bBackground )
196 SetBackground( rStyleSettings.GetFieldColor() );
200 //==================================================================
201 // class OAppDetailPageHelper
202 DBG_NAME(OAppDetailPageHelper)
203 //==================================================================
204 OAppDetailPageHelper::OAppDetailPageHelper(Window* _pParent,OAppBorderWindow& _rBorderWin,PreviewMode _ePreviewMode) : Window(_pParent,WB_DIALOGCONTROL)
205 ,m_rBorderWin(_rBorderWin)
206 ,m_aFL(this,WB_VERT)
207 ,m_aTBPreview(this,WB_TABSTOP )
208 ,m_aBorder(this,WB_BORDER | WB_READONLY)
209 ,m_aPreview(&m_aBorder)
210 ,m_aDocumentInfo(&m_aBorder,WB_LEFT | WB_VSCROLL | WB_READONLY )
211 ,m_pTablePreview(NULL)
212 ,m_ePreviewMode(_ePreviewMode)
214 DBG_CTOR(OAppDetailPageHelper,NULL);
216 m_aBorder.SetBorderStyle(WINDOW_BORDER_MONO);
218 m_aMenu.reset(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
220 m_aTBPreview.SetOutStyle(TOOLBOX_STYLE_FLAT);
221 m_aTBPreview.InsertItem(SID_DB_APP_DISABLE_PREVIEW,m_aMenu->GetItemText(SID_DB_APP_DISABLE_PREVIEW),TIB_LEFT|TIB_DROPDOWN|TIB_AUTOSIZE|TIB_RADIOCHECK);
222 m_aTBPreview.SetHelpId(HID_APP_VIEW_PREVIEW_CB);
223 m_aTBPreview.SetDropdownClickHdl( LINK( this, OAppDetailPageHelper, OnDropdownClickHdl ) );
224 m_aTBPreview.EnableMenuStrings();
225 m_aTBPreview.Enable(sal_True);
227 m_aBorder.SetUniqueId(UID_APP_VIEW_PREVIEW_1);
229 m_aPreview.SetHelpId(HID_APP_VIEW_PREVIEW_1);
231 m_pTablePreview = new OTablePreviewWindow(&m_aBorder,WB_READONLY | WB_DIALOGCONTROL );
232 m_pTablePreview->SetHelpId(HID_APP_VIEW_PREVIEW_2);
234 m_aDocumentInfo.SetHelpId(HID_APP_VIEW_PREVIEW_3);
236 m_xWindow = VCLUnoHelper::GetInterface( m_pTablePreview );
238 SetUniqueId(UID_APP_DETAILPAGE_HELPER);
239 for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
240 m_pLists[i] = NULL;
241 ImplInitSettings();
243 // -----------------------------------------------------------------------------
244 OAppDetailPageHelper::~OAppDetailPageHelper()
248 Reference< ::util::XCloseable> xCloseable(m_xFrame,UNO_QUERY);
249 if ( xCloseable.is() )
250 xCloseable->close(sal_True);
252 catch(const Exception&)
254 OSL_FAIL("Exception thrown while disposing preview frame!");
257 for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
259 if ( m_pLists[i] )
261 m_pLists[i]->clearCurrentSelection();
262 m_pLists[i]->Hide();
263 SAL_WNODEPRECATED_DECLARATIONS_PUSH
264 ::std::auto_ptr<DBTreeListBox> aTemp(m_pLists[i]);
265 SAL_WNODEPRECATED_DECLARATIONS_POP
266 m_pLists[i]->clearCurrentSelection(); // why a second time?
267 m_pLists[i] = NULL;
272 DBG_DTOR(OAppDetailPageHelper,NULL);
274 // -----------------------------------------------------------------------------
275 int OAppDetailPageHelper::getVisibleControlIndex() const
277 int i = 0;
278 for (; i < E_ELEMENT_TYPE_COUNT ; ++i)
280 if ( m_pLists[i] && m_pLists[i]->IsVisible() )
281 break;
283 return i;
285 // -----------------------------------------------------------------------------
286 void OAppDetailPageHelper::selectAll()
288 int nPos = getVisibleControlIndex();
289 if ( nPos < E_ELEMENT_TYPE_COUNT )
291 m_pLists[nPos]->SelectAll(sal_True);
294 // -----------------------------------------------------------------------------
295 void OAppDetailPageHelper::sort(int _nPos,SvSortMode _eSortMode )
297 OSL_ENSURE(m_pLists[_nPos],"List can not be NULL! ->GPF");
298 SvLBoxTreeList* pModel = m_pLists[_nPos]->GetModel();
299 SvSortMode eOldSortMode = pModel->GetSortMode();
300 pModel->SetSortMode(_eSortMode);
301 if ( eOldSortMode != _eSortMode )
302 pModel->Resort();
304 // -----------------------------------------------------------------------------
305 sal_Bool OAppDetailPageHelper::isSortUp() const
307 SvSortMode eSortMode = SortNone;
308 int nPos = getVisibleControlIndex();
309 if ( nPos < E_ELEMENT_TYPE_COUNT )
311 SvLBoxTreeList* pModel = m_pLists[nPos]->GetModel();
312 eSortMode = pModel->GetSortMode();
314 return eSortMode == SortAscending;
316 // -----------------------------------------------------------------------------
317 void OAppDetailPageHelper::sortDown()
319 int nPos = getVisibleControlIndex();
320 if ( nPos < E_ELEMENT_TYPE_COUNT )
321 sort(nPos,SortDescending);
323 // -----------------------------------------------------------------------------
324 void OAppDetailPageHelper::sortUp()
326 int nPos = getVisibleControlIndex();
327 if ( nPos < E_ELEMENT_TYPE_COUNT )
328 sort(nPos,SortAscending);
330 // -----------------------------------------------------------------------------
331 void OAppDetailPageHelper::getSelectionElementNames( ::std::vector< ::rtl::OUString>& _rNames ) const
333 int nPos = getVisibleControlIndex();
334 if ( nPos < E_ELEMENT_TYPE_COUNT )
336 DBTreeListBox& rTree = *m_pLists[nPos];
337 sal_Int32 nCount = rTree.GetEntryCount();
338 _rNames.reserve(nCount);
339 SvLBoxEntry* pEntry = rTree.FirstSelected();
340 ElementType eType = getElementType();
341 while( pEntry )
343 if ( eType == E_TABLE )
345 if( rTree.GetChildCount(pEntry) == 0 )
346 _rNames.push_back( getQualifiedName( pEntry ) );
348 else
350 ::rtl::OUString sName = rTree.GetEntryText(pEntry);
351 SvLBoxEntry* pParent = rTree.GetParent(pEntry);
352 while(pParent)
354 sName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
355 pParent = rTree.GetParent(pParent);
357 _rNames.push_back(sName);
359 pEntry = rTree.NextSelected(pEntry);
364 // -----------------------------------------------------------------------------
365 void OAppDetailPageHelper::describeCurrentSelectionForControl( const Control& _rControl, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
367 enum ElementType eType = E_TABLE;
368 for ( size_t i=0; i < E_ELEMENT_TYPE_COUNT; eType = static_cast< ElementType >( ++i ) )
370 if ( m_pLists[eType] == &_rControl )
372 describeCurrentSelectionForType( eType, _out_rSelectedObjects );
373 return;
376 OSL_FAIL( "OAppDetailPageHelper::describeCurrentSelectionForControl: invalid control!" );
379 // -----------------------------------------------------------------------------
380 void OAppDetailPageHelper::describeCurrentSelectionForType( const ElementType _eType, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
382 OSL_ENSURE( _eType < E_ELEMENT_TYPE_COUNT, "OAppDetailPageHelper::describeCurrentSelectionForType: invalid type!" );
383 DBTreeListBox* pList = ( _eType < E_ELEMENT_TYPE_COUNT ) ? m_pLists[ _eType ] : NULL;
384 OSL_ENSURE( pList, "OAppDetailPageHelper::describeCurrentSelectionForType: "
385 "You really should ensure this type has already been viewed before!" );
386 if ( !pList )
387 return;
389 ::std::vector< NamedDatabaseObject > aSelected;
391 SvLBoxEntry* pEntry = pList->FirstSelected();
392 while( pEntry )
394 NamedDatabaseObject aObject;
395 switch ( _eType )
397 case E_TABLE:
399 OTableTreeListBox& rTableTree = dynamic_cast< OTableTreeListBox& >( *pList );
400 aObject = rTableTree.describeObject( pEntry );
402 break;
403 case E_QUERY:
404 aObject.Type = DatabaseObject::QUERY;
405 aObject.Name = pList->GetEntryText( pEntry );
406 break;
408 case E_FORM:
409 case E_REPORT:
411 ::rtl::OUString sName = pList->GetEntryText(pEntry);
412 SvLBoxEntry* pParent = pList->GetParent(pEntry);
413 while ( pParent )
415 ::rtl::OUStringBuffer buffer;
416 buffer.append( pList->GetEntryText( pParent ) );
417 buffer.append( sal_Unicode( '/' ) );
418 buffer.append( sName );
419 sName = buffer.makeStringAndClear();
421 pParent = pList->GetParent( pParent );
424 if ( isLeaf( pEntry ) )
425 aObject.Type = ( _eType == E_FORM ) ? DatabaseObject::FORM : DatabaseObject::REPORT;
426 else
427 aObject.Type = ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER : DatabaseObjectContainer::REPORTS_FOLDER;
428 aObject.Name = sName;
430 break;
431 default:
432 OSL_FAIL( "OAppDetailPageHelper::describeCurrentSelectionForType: unexpected type!" );
433 break;
436 if ( !aObject.Name.isEmpty() )
438 aSelected.push_back( aObject );
441 pEntry = pList->NextSelected(pEntry);
444 _out_rSelectedObjects.realloc( aSelected.size() );
445 ::std::copy( aSelected.begin(), aSelected.end(), _out_rSelectedObjects.getArray() );
448 // -----------------------------------------------------------------------------
449 void OAppDetailPageHelper::selectElements(const Sequence< ::rtl::OUString>& _aNames)
451 int nPos = getVisibleControlIndex();
452 if ( nPos < E_ELEMENT_TYPE_COUNT )
454 DBTreeListBox& rTree = *m_pLists[nPos];
455 rTree.SelectAll(sal_False);
456 const ::rtl::OUString* pIter = _aNames.getConstArray();
457 const ::rtl::OUString* pEnd = pIter + _aNames.getLength();
458 for(;pIter != pEnd;++pIter)
460 SvLBoxEntry* pEntry = rTree.GetEntryPosByName(*pIter);
461 if ( pEntry )
462 rTree.Select(pEntry);
466 // -----------------------------------------------------------------------------
467 ::rtl::OUString OAppDetailPageHelper::getQualifiedName( SvLBoxEntry* _pEntry ) const
469 int nPos = getVisibleControlIndex();
470 ::rtl::OUString sComposedName;
472 if ( nPos >= E_ELEMENT_TYPE_COUNT )
473 return sComposedName;
475 OSL_ENSURE(m_pLists[nPos],"Tables tree view is NULL! -> GPF");
476 DBTreeListBox& rTree = *m_pLists[nPos];
478 SvLBoxEntry* pEntry = _pEntry;
479 if ( !pEntry )
480 pEntry = rTree.FirstSelected();
482 if ( !pEntry )
483 return sComposedName;
485 if ( getElementType() == E_TABLE )
487 const OTableTreeListBox& rTreeView = dynamic_cast< const OTableTreeListBox& >( *m_pLists[nPos] );
488 sComposedName = rTreeView.getQualifiedTableName( pEntry );
490 else
492 sComposedName = rTree.GetEntryText(pEntry);
493 SvLBoxEntry* pParent = rTree.GetParent(pEntry);
494 while(pParent)
496 sComposedName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sComposedName;
497 pParent = rTree.GetParent(pParent);
501 return sComposedName;
503 // -----------------------------------------------------------------------------
504 ElementType OAppDetailPageHelper::getElementType() const
506 int nPos = getVisibleControlIndex();
507 return static_cast<ElementType>(nPos);
509 // -----------------------------------------------------------------------------
510 sal_Int32 OAppDetailPageHelper::getSelectionCount()
512 sal_Int32 nCount = 0;
513 int nPos = getVisibleControlIndex();
514 if ( nPos < E_ELEMENT_TYPE_COUNT )
516 DBTreeListBox& rTree = *m_pLists[nPos];
517 SvLBoxEntry* pEntry = rTree.FirstSelected();
518 while( pEntry )
520 ++nCount;
521 pEntry = rTree.NextSelected(pEntry);
524 return nCount;
526 // -----------------------------------------------------------------------------
527 sal_Int32 OAppDetailPageHelper::getElementCount()
529 sal_Int32 nCount = 0;
530 int nPos = getVisibleControlIndex();
531 if ( nPos < E_ELEMENT_TYPE_COUNT )
533 nCount = m_pLists[nPos]->GetEntryCount();
535 return nCount;
537 // -----------------------------------------------------------------------------
538 sal_Bool OAppDetailPageHelper::isCutAllowed()
540 return sal_False;
542 // -----------------------------------------------------------------------------
543 sal_Bool OAppDetailPageHelper::isCopyAllowed()
545 return sal_True;
547 // -----------------------------------------------------------------------------
548 sal_Bool OAppDetailPageHelper::isPasteAllowed()
550 return sal_True;
552 // -----------------------------------------------------------------------------
553 void OAppDetailPageHelper::copy()
556 // -----------------------------------------------------------------------------
557 void OAppDetailPageHelper::cut()
560 // -----------------------------------------------------------------------------
561 void OAppDetailPageHelper::paste()
564 // -----------------------------------------------------------------------------
565 bool OAppDetailPageHelper::isLeaf(SvLBoxEntry* _pEntry) const
567 if ( !_pEntry )
568 return false;
569 sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() );
570 if ( ( nEntryType == DatabaseObjectContainer::TABLES )
571 || ( nEntryType == DatabaseObjectContainer::CATALOG )
572 || ( nEntryType == DatabaseObjectContainer::SCHEMA )
573 || ( nEntryType == DatabaseObjectContainer::FORMS_FOLDER )
574 || ( nEntryType == DatabaseObjectContainer::REPORTS_FOLDER )
576 return false;
578 return true;
581 // -----------------------------------------------------------------------------
582 sal_Bool OAppDetailPageHelper::isALeafSelected() const
584 int nPos = getVisibleControlIndex();
585 sal_Bool bLeafSelected = sal_False;
586 if ( nPos < E_ELEMENT_TYPE_COUNT )
588 DBTreeListBox& rTree = *m_pLists[nPos];
589 SvLBoxEntry* pEntry = rTree.FirstSelected( );
590 while( !bLeafSelected && pEntry )
592 bLeafSelected = isLeaf( pEntry );
593 pEntry = rTree.NextSelected(pEntry);
596 return bLeafSelected;
598 // -----------------------------------------------------------------------------
599 SvLBoxEntry* OAppDetailPageHelper::getEntry( const Point& _aPosPixel) const
601 SvLBoxEntry* pReturn = NULL;
602 int nPos = getVisibleControlIndex();
603 if ( nPos < E_ELEMENT_TYPE_COUNT )
604 pReturn = m_pLists[nPos]->GetEntry( _aPosPixel,sal_True );
605 return pReturn;
607 // -----------------------------------------------------------------------------
608 void OAppDetailPageHelper::createTablesPage(const Reference< XConnection>& _xConnection)
610 OSL_ENSURE(_xConnection.is(),"Connection is NULL! -> GPF");
612 if ( !m_pLists[E_TABLE] )
614 OTableTreeListBox* pTreeView = new OTableTreeListBox(this
615 ,getBorderWin().getView()->getORB()
616 ,WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP
617 ,sal_False);
618 pTreeView->SetHelpId(HID_APP_TABLE_TREE);
619 m_pLists[E_TABLE] = pTreeView;
621 ImageProvider aImageProvider( _xConnection );
622 createTree( pTreeView,
623 aImageProvider.getDefaultImage( DatabaseObject::TABLE )
626 pTreeView->notifyHiContrastChanged();
627 m_aBorder.SetZOrder(pTreeView, WINDOW_ZORDER_BEHIND);
629 if ( !m_pLists[E_TABLE]->GetEntryCount() )
631 static_cast<OTableTreeListBox*>(m_pLists[E_TABLE])->UpdateTableList(_xConnection);
633 SvLBoxEntry* pEntry = m_pLists[E_TABLE]->First();
634 if ( pEntry )
635 m_pLists[E_TABLE]->Expand(pEntry);
636 m_pLists[E_TABLE]->SelectAll(sal_False);
639 setDetailPage(m_pLists[E_TABLE]);
642 // -----------------------------------------------------------------------------
643 void OAppDetailPageHelper::getElementIcons( ElementType _eType, sal_uInt16& _rImageId)
645 ImageProvider aImageProvider;
646 _rImageId = 0;
648 sal_Int32 nDatabaseObjectType( 0 );
649 switch(_eType )
651 case E_FORM: nDatabaseObjectType = DatabaseObject::FORM; break;
652 case E_REPORT: nDatabaseObjectType = DatabaseObject::REPORT; break;
653 case E_QUERY: nDatabaseObjectType = DatabaseObject::QUERY; break;
654 default:
655 OSL_FAIL( "OAppDetailPageHelper::GetElementIcons: invalid element type!" );
656 return;
658 _rImageId = aImageProvider.getDefaultImageResourceID( nDatabaseObjectType );
661 // -----------------------------------------------------------------------------
662 void OAppDetailPageHelper::createPage(ElementType _eType,const Reference< XNameAccess >& _xContainer)
664 OSL_ENSURE(E_TABLE != _eType,"E_TABLE isn't allowed.");
666 sal_uInt16 nImageId = 0;
667 rtl::OString sHelpId;
668 ImageProvider aImageProvider;
669 Image aFolderImage;
670 switch( _eType )
672 case E_FORM:
673 sHelpId = HID_APP_FORM_TREE;
674 aFolderImage = aImageProvider.getFolderImage( DatabaseObject::FORM );
675 break;
676 case E_REPORT:
677 sHelpId = HID_APP_REPORT_TREE;
678 aFolderImage = aImageProvider.getFolderImage( DatabaseObject::REPORT );
679 break;
680 case E_QUERY:
681 sHelpId = HID_APP_QUERY_TREE;
682 aFolderImage = aImageProvider.getFolderImage( DatabaseObject::QUERY );
683 break;
684 default:
685 OSL_FAIL("Illegal call!");
687 getElementIcons( _eType, nImageId );
689 if ( !m_pLists[_eType] )
691 m_pLists[_eType] = createSimpleTree( sHelpId, aFolderImage );
694 if ( m_pLists[_eType] )
696 if ( !m_pLists[_eType]->GetEntryCount() && _xContainer.is() )
698 fillNames( _xContainer, _eType, nImageId, NULL );
700 m_pLists[_eType]->SelectAll(sal_False);
702 setDetailPage(m_pLists[_eType]);
705 // -----------------------------------------------------------------------------
706 void OAppDetailPageHelper::setDetailPage(Window* _pWindow)
708 OSL_ENSURE(_pWindow,"OAppDetailPageHelper::setDetailPage: Window is NULL!");
709 Window* pCurrent = getCurrentView();
710 if ( pCurrent )
711 pCurrent->Hide();
713 showPreview(NULL);
714 sal_Bool bHasFocus = sal_False;
715 m_aFL.Show();
717 bHasFocus = pCurrent->HasChildPathFocus();
718 _pWindow->Show();
720 m_aTBPreview.Show();
721 m_aBorder.Show();
722 switchPreview(m_ePreviewMode,sal_True);
724 if ( bHasFocus )
725 _pWindow->GrabFocus();
726 Resize();
729 // -----------------------------------------------------------------------------
730 namespace
732 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
733 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
735 static sal_Int32 lcl_getFolderIndicatorForType( const ElementType _eType )
737 const sal_Int32 nFolderIndicator =
738 ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER
739 : ( _eType == E_REPORT ) ? DatabaseObjectContainer::REPORTS_FOLDER : -1;
740 return nFolderIndicator;
744 // -----------------------------------------------------------------------------
745 void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, const ElementType _eType,
746 const sal_uInt16 _nImageId, SvLBoxEntry* _pParent )
748 OSL_ENSURE(_xContainer.is(),"Data source is NULL! -> GPF");
749 OSL_ENSURE( ( _eType >= E_TABLE ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OAppDetailPageHelper::fillNames: invalid type!" );
751 DBTreeListBox* pList = m_pLists[ _eType ];
752 OSL_ENSURE( pList, "OAppDetailPageHelper::fillNames: you really should create the list before calling this!" );
753 if ( !pList )
754 return;
756 if ( _xContainer.is() && _xContainer->hasElements() )
758 const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
760 Sequence< ::rtl::OUString> aSeq = _xContainer->getElementNames();
761 const ::rtl::OUString* pIter = aSeq.getConstArray();
762 const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
763 for(;pIter != pEnd;++pIter)
765 SvLBoxEntry* pEntry = NULL;
766 Reference<XNameAccess> xSubElements(_xContainer->getByName(*pIter),UNO_QUERY);
767 if ( xSubElements.is() )
769 pEntry = pList->InsertEntry( *pIter, _pParent, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
770 getBorderWin().getView()->getAppController().containerFound( Reference< XContainer >( xSubElements, UNO_QUERY ) );
771 fillNames( xSubElements, _eType, _nImageId, pEntry );
773 else
775 pEntry = pList->InsertEntry( *pIter, _pParent );
777 Image aImage = Image( ModuleRes( _nImageId ) );
778 pList->SetExpandedEntryBmp( pEntry, aImage );
779 pList->SetCollapsedEntryBmp( pEntry, aImage );
784 // -----------------------------------------------------------------------------
785 DBTreeListBox* OAppDetailPageHelper::createSimpleTree( const rtl::OString& _sHelpId, const Image& _rImage)
787 DBTreeListBox* pTreeView = new DBTreeListBox(this,getBorderWin().getView()->getORB(),WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
788 pTreeView->SetHelpId( _sHelpId );
789 return createTree( pTreeView, _rImage );
792 // -----------------------------------------------------------------------------
793 DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, const Image& _rImage )
795 WaitObject aWaitCursor(this);
797 _pTreeView->SetStyle(_pTreeView->GetStyle() | WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
798 _pTreeView->GetModel()->SetSortMode(SortAscending);
799 _pTreeView->EnableCheckButton( NULL ); // do not show any buttons
800 _pTreeView->SetSelectionMode(MULTIPLE_SELECTION);
802 _pTreeView->SetDefaultCollapsedEntryBmp( _rImage );
803 _pTreeView->SetDefaultExpandedEntryBmp( _rImage );
805 _pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
806 _pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
807 _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
809 _pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
810 _pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
811 _pTreeView->setPasteHandler(LINK(this, OAppDetailPageHelper, OnPasteEntry));
812 _pTreeView->setDeleteHandler(LINK(this, OAppDetailPageHelper, OnDeleteEntry));
814 _pTreeView->setControlActionListener( &getBorderWin().getView()->getAppController() );
815 _pTreeView->setContextMenuProvider( &getBorderWin().getView()->getAppController() );
817 return _pTreeView;
819 // -----------------------------------------------------------------------------
820 void OAppDetailPageHelper::clearPages()
822 showPreview(NULL);
823 for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
825 if ( m_pLists[i] )
826 m_pLists[i]->Clear();
829 // -----------------------------------------------------------------------------
830 sal_Bool OAppDetailPageHelper::isFilled() const
832 size_t i = 0;
833 for (; i < E_ELEMENT_TYPE_COUNT && !m_pLists[i]; ++i)
835 return i != E_ELEMENT_TYPE_COUNT;
837 // -----------------------------------------------------------------------------
838 void OAppDetailPageHelper::elementReplaced(ElementType _eType
839 ,const ::rtl::OUString& _rOldName
840 ,const ::rtl::OUString& _rNewName )
842 DBTreeListBox* pTreeView = getCurrentView();
843 if ( pTreeView )
845 ::rtl::OUString sNewName = _rNewName;
846 SvLBoxEntry* pEntry = NULL;
847 switch( _eType )
849 case E_TABLE:
850 static_cast<OTableTreeListBox*>(pTreeView)->removedTable( _rOldName );
851 static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rNewName );
852 return;
854 case E_QUERY:
855 pEntry = lcl_findEntry_impl(*pTreeView,_rOldName,pTreeView->First());
856 break;
857 case E_FORM:
858 case E_REPORT:
859 pEntry = lcl_findEntry(*pTreeView,_rOldName,pTreeView->First());
860 break;
861 default:
862 OSL_FAIL("Invalid element type");
864 OSL_ENSURE(pEntry,"Do you know that the name isn't existence!");
865 if ( pEntry )
867 pTreeView->SetEntryText(pEntry,sNewName);
871 // -----------------------------------------------------------------------------
872 SvLBoxEntry* OAppDetailPageHelper::elementAdded(ElementType _eType,const ::rtl::OUString& _rName, const Any& _rObject )
874 SvLBoxEntry* pRet = NULL;
875 DBTreeListBox* pTreeView = m_pLists[_eType];
876 if( _eType == E_TABLE && pTreeView )
878 pRet = static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rName );
880 else if ( pTreeView )
883 SvLBoxEntry* pEntry = NULL;
884 Reference<XChild> xChild(_rObject,UNO_QUERY);
885 if ( xChild.is() && E_QUERY != _eType )
887 Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
888 if ( xContent.is() )
890 ::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
891 pEntry = lcl_findEntry(*pTreeView,sName,pTreeView->First());
895 sal_uInt16 nImageId = 0;
896 getElementIcons( _eType, nImageId );
897 Reference<XNameAccess> xContainer(_rObject,UNO_QUERY);
898 if ( xContainer.is() )
900 const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
901 pRet = pTreeView->InsertEntry( _rName, pEntry, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
902 fillNames( xContainer, _eType, nImageId, pRet );
904 else
906 pRet = pTreeView->InsertEntry( _rName, pEntry );
908 Image aImage = Image( ModuleRes( nImageId ) );
909 pTreeView->SetExpandedEntryBmp( pRet, aImage );
910 pTreeView->SetCollapsedEntryBmp( pRet, aImage );
913 return pRet;
915 // -----------------------------------------------------------------------------
916 void OAppDetailPageHelper::elementRemoved( ElementType _eType,const ::rtl::OUString& _rName )
918 DBTreeListBox* pTreeView = getCurrentView();
919 if ( pTreeView )
921 switch( _eType )
923 case E_TABLE:
924 // we don't need to clear the table here, it is already done by the dispose listener
925 static_cast< OTableTreeListBox* >( pTreeView )->removedTable( _rName );
926 break;
927 case E_QUERY:
928 if ( pTreeView )
930 SvLBoxEntry* pEntry = lcl_findEntry_impl(*pTreeView,_rName,pTreeView->First());
931 if ( pEntry )
932 pTreeView->GetModel()->Remove(pEntry);
934 break;
935 case E_FORM:
936 case E_REPORT:
938 if ( pTreeView )
940 SvLBoxEntry* pEntry = lcl_findEntry(*pTreeView,_rName,pTreeView->First());
941 if ( pEntry )
942 pTreeView->GetModel()->Remove(pEntry);
945 break;
946 default:
947 OSL_FAIL("Invalid element type");
949 if ( !pTreeView->GetEntryCount() )
950 showPreview(NULL);
953 // -----------------------------------------------------------------------------
954 IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
956 OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnEntryDoubleClick: invalid callback!" );
957 bool bHandled = ( _pTree != NULL ) && getBorderWin().getView()->getAppController().onEntryDoubleClick( *_pTree );
958 return bHandled ? 1L : 0L;
960 // -----------------------------------------------------------------------------
961 IMPL_LINK(OAppDetailPageHelper, OnEntrySelChange, void*, /*NOINTERESTEDIN*/)
963 getBorderWin().getView()->getAppController().onSelectionChanged();
964 return 1L;
966 // -----------------------------------------------------------------------------
967 IMPL_LINK( OAppDetailPageHelper, OnCutEntry, void*, /*NOINTERESTEDIN*/ )
969 getBorderWin().getView()->getAppController().onCutEntry();
970 return 1L;
972 // -----------------------------------------------------------------------------
973 IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, void*, /*NOINTERESTEDIN*/ )
975 getBorderWin().getView()->getAppController().onCopyEntry();
976 return 1L;
978 // -----------------------------------------------------------------------------
979 IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, void*, /*NOINTERESTEDIN*/ )
981 getBorderWin().getView()->getAppController().onPasteEntry();
982 return 1L;
984 // -----------------------------------------------------------------------------
985 IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, void*, /*NOINTERESTEDIN*/ )
987 getBorderWin().getView()->getAppController().onDeleteEntry();
988 return 1L;
990 // -----------------------------------------------------------------------------
991 void OAppDetailPageHelper::Resize()
993 // parent window dimension
994 Size aOutputSize( GetOutputSize() );
995 long nOutputWidth = aOutputSize.Width();
996 long nOutputHeight = aOutputSize.Height();
998 Window* pWindow = getCurrentView();
999 if ( pWindow )
1001 Size aFLSize = LogicToPixel( Size( 2, 6 ), MAP_APPFONT );
1002 sal_Int32 n6PPT = aFLSize.Height();
1003 long nHalfOutputWidth = static_cast<long>(nOutputWidth * 0.5);
1005 pWindow->SetPosSizePixel( Point(0, 0), Size(nHalfOutputWidth - n6PPT, nOutputHeight) );
1007 m_aFL.SetPosSizePixel( Point(nHalfOutputWidth , 0 ), Size(aFLSize.Width(), nOutputHeight ) );
1009 String sText = m_aTBPreview.GetItemText(SID_DB_APP_DISABLE_PREVIEW);
1010 Size aTBSize = m_aTBPreview.CalcWindowSizePixel();
1011 m_aTBPreview.SetPosSizePixel(Point(nOutputWidth - aTBSize.getWidth(), 0 ),
1012 aTBSize );
1014 m_aBorder.SetPosSizePixel(Point(nHalfOutputWidth + aFLSize.Width() + n6PPT, aTBSize.getHeight() + n6PPT ),
1015 Size(nHalfOutputWidth - aFLSize.Width() - n6PPT, nOutputHeight - 2*n6PPT - aTBSize.getHeight()) );
1016 m_aPreview.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1017 m_aDocumentInfo.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1018 m_pTablePreview->SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1021 // -----------------------------------------------------------------------------
1022 PreviewMode OAppDetailPageHelper::getPreviewMode()
1024 return m_ePreviewMode;
1026 // -----------------------------------------------------------------------------
1027 sal_Bool OAppDetailPageHelper::isPreviewEnabled()
1029 return m_ePreviewMode != E_PREVIEWNONE;
1031 // -----------------------------------------------------------------------------
1032 void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,sal_Bool _bForce)
1034 if ( m_ePreviewMode != _eMode || _bForce )
1036 m_ePreviewMode = _eMode;
1038 getBorderWin().getView()->getAppController().previewChanged(static_cast<sal_Int32>(m_ePreviewMode));
1040 sal_uInt16 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1041 switch ( m_ePreviewMode )
1043 case E_PREVIEWNONE:
1044 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1045 break;
1046 case E_DOCUMENT:
1047 nSelectedAction = SID_DB_APP_VIEW_DOC_PREVIEW;
1048 break;
1049 case E_DOCUMENTINFO:
1050 if ( getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) )
1051 nSelectedAction = SID_DB_APP_VIEW_DOCINFO_PREVIEW;
1052 else
1053 m_ePreviewMode = E_PREVIEWNONE;
1054 break;
1057 m_aMenu->CheckItem(nSelectedAction);
1058 m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
1059 Resize();
1061 // simulate a selectionChanged event at the controller, to force the preview to be updated
1062 if ( isPreviewEnabled() )
1064 if ( getCurrentView() && getCurrentView()->FirstSelected() )
1066 getBorderWin().getView()->getAppController().onSelectionChanged();
1069 else
1071 m_pTablePreview->Hide();
1072 m_aPreview.Hide();
1073 m_aDocumentInfo.Hide();
1077 // -----------------------------------------------------------------------------
1078 void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
1080 if ( isPreviewEnabled() )
1082 m_pTablePreview->Hide();
1084 WaitObject aWaitCursor( this );
1087 Reference<XCommandProcessor> xContent(_xContent,UNO_QUERY);
1088 if ( xContent.is() )
1090 com::sun::star::ucb::Command aCommand;
1091 if ( m_ePreviewMode == E_DOCUMENT )
1092 aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("preview"));
1093 else
1094 aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getDocumentInfo"));
1096 Any aPreview = xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
1097 if ( m_ePreviewMode == E_DOCUMENT )
1099 m_aDocumentInfo.Hide();
1100 m_aPreview.Show();
1102 Graphic aGraphic;
1103 Sequence < sal_Int8 > aBmpSequence;
1104 if ( aPreview >>= aBmpSequence )
1106 SvMemoryStream aData( aBmpSequence.getArray(),
1107 aBmpSequence.getLength(),
1108 STREAM_READ );
1110 GraphicConverter::Import(aData,aGraphic);
1112 m_aPreview.setGraphic( aGraphic );
1113 m_aPreview.Invalidate();
1115 else
1117 m_aPreview.Hide();
1118 m_aDocumentInfo.clear();
1119 m_aDocumentInfo.Show();
1120 Reference<document::XDocumentProperties> xProp(
1121 aPreview, UNO_QUERY);
1122 if ( xProp.is() )
1123 m_aDocumentInfo.fill(xProp,String());
1126 else
1128 m_aPreview.Hide();
1129 m_aDocumentInfo.Hide();
1132 catch( const Exception& )
1134 DBG_UNHANDLED_EXCEPTION();
1138 // -----------------------------------------------------------------------------
1139 void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName,
1140 const ::rtl::OUString& _sName,
1141 sal_Bool _bTable)
1143 if ( isPreviewEnabled() )
1145 WaitObject aWaitCursor( this );
1146 m_aPreview.Hide();
1147 m_aDocumentInfo.Hide();
1148 m_pTablePreview->Show();
1149 if ( !m_xFrame.is() )
1153 m_xFrame = Reference < XFrame > ( getBorderWin().getView()->getORB()->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Frame")) ), UNO_QUERY );
1154 m_xFrame->initialize( m_xWindow );
1156 // no layout manager (and thus no toolbars) in the preview
1157 // Must be called after initialize ... but before any other call to this frame.
1158 // Otherwise frame throws "life time exceptions" as e.g. NON_INITIALIZED
1159 Reference< XPropertySet > xFrameProps( m_xFrame, UNO_QUERY_THROW );
1160 xFrameProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ), makeAny(Reference< XLayoutManager >()) );
1162 Reference<XFramesSupplier> xSup(getBorderWin().getView()->getAppController().getXController()->getFrame(),UNO_QUERY);
1163 if ( xSup.is() )
1165 Reference<XFrames> xFrames = xSup->getFrames();
1166 xFrames->append(m_xFrame);
1169 catch(const Exception&)
1174 Reference< XDatabaseDocumentUI > xApplication( getBorderWin().getView()->getAppController().getXController(), UNO_QUERY );
1175 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1176 ::std::auto_ptr< DatabaseObjectView > pDispatcher( new ResultSetBrowser(
1177 getBorderWin().getView()->getORB(), xApplication, NULL, _bTable
1178 ) );
1179 SAL_WNODEPRECATED_DECLARATIONS_POP
1180 pDispatcher->setTargetFrame( m_xFrame );
1182 ::comphelper::NamedValueCollection aArgs;
1183 aArgs.put( "Preview", sal_True );
1184 aArgs.put( "ReadOnly", sal_True );
1185 aArgs.put( "AsTemplate", sal_False );
1186 aArgs.put( (::rtl::OUString)PROPERTY_SHOWMENU, sal_False );
1188 Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY );
1189 sal_Bool bClearPreview = !xPreview.is();
1191 // clear the preview when the query or table could not be loaded
1192 if ( !bClearPreview )
1194 Reference< XTabController > xTabController( xPreview, UNO_QUERY );
1195 bClearPreview = !xTabController.is();
1196 if ( !bClearPreview )
1198 Reference< XLoadable > xLoadable( xTabController->getModel(), UNO_QUERY );
1199 bClearPreview = !( xLoadable.is() && xLoadable->isLoaded() );
1202 if ( bClearPreview )
1203 showPreview(NULL);
1206 // -----------------------------------------------------------------------------
1207 IMPL_LINK(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, /*pToolBox*/)
1209 m_aTBPreview.EndSelection();
1211 // tell the toolbox that the item is pressed down
1212 m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_True );
1214 // simulate a mouse move (so the "down" state is really painted)
1215 Point aPoint = m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ).TopLeft();
1216 MouseEvent aMove( aPoint, 0, MOUSE_SIMPLEMOVE | MOUSE_SYNTHETIC );
1217 m_aTBPreview.MouseMove( aMove );
1219 m_aTBPreview.Update();
1221 // execute the menu
1222 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1223 ::std::auto_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
1224 SAL_WNODEPRECATED_DECLARATIONS_POP
1226 sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
1227 , SID_DB_APP_VIEW_DOC_PREVIEW
1228 , SID_DB_APP_VIEW_DOCINFO_PREVIEW
1231 for(size_t i=0; i < sizeof(pActions)/sizeof(pActions[0]);++i)
1233 aMenu->CheckItem(pActions[i],m_aMenu->IsItemChecked(pActions[i]));
1235 aMenu->EnableItem( SID_DB_APP_VIEW_DOCINFO_PREVIEW, getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) );
1237 // no disabled entries
1238 aMenu->RemoveDisabledEntries();
1240 sal_uInt16 nSelectedAction = aMenu->Execute(&m_aTBPreview, m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ));
1241 // "cleanup" the toolbox state
1242 MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
1243 m_aTBPreview.MouseMove( aLeave );
1244 m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_False);
1245 if ( nSelectedAction )
1247 m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, aMenu->GetItemText(nSelectedAction));
1248 Resize();
1249 getBorderWin().getView()->getAppController().executeChecked(nSelectedAction,Sequence<PropertyValue>());
1251 return 0L;
1254 // -----------------------------------------------------------------------------
1255 void OAppDetailPageHelper::KeyInput( const KeyEvent& rKEvt )
1257 SvTreeListBox* pCurrentView = getCurrentView();
1258 OSL_PRECOND( pCurrentView, "OAppDetailPageHelper::KeyInput: how this?" );
1260 KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); (void)eFunc;
1261 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1263 if ( ( KEY_RETURN == nCode ) && pCurrentView )
1265 getBorderWin().getView()->getAppController().onEntryDoubleClick( *pCurrentView );
1267 else
1268 Window::KeyInput(rKEvt);
1271 // -----------------------------------------------------------------------------
1272 void OAppDetailPageHelper::DataChanged( const DataChangedEvent& rDCEvt )
1274 Window::DataChanged( rDCEvt );
1276 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1277 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1278 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1279 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1280 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1283 ImplInitSettings();
1284 if ( m_pLists[ E_TABLE ] )
1286 OTableTreeListBox* pTableTree = dynamic_cast< OTableTreeListBox* >( m_pLists[ E_TABLE ] );
1287 OSL_ENSURE( pTableTree != NULL, "OAppDetailPageHelper::DataChanged: a tree list for tables which is no TableTreeList?" );
1288 if ( pTableTree )
1289 pTableTree->notifyHiContrastChanged();
1293 // -----------------------------------------------------------------------------
1294 void OAppDetailPageHelper::ImplInitSettings()
1296 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1297 Font aFont;
1298 aFont = rStyleSettings.GetFieldFont();
1299 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1300 SetPointFont( aFont );
1301 m_aTBPreview.SetPointFont( aFont );
1303 SetTextColor( rStyleSettings.GetFieldTextColor() );
1304 SetTextFillColor();
1305 m_aBorder.SetTextColor( rStyleSettings.GetFieldTextColor() );
1306 m_aBorder.SetTextFillColor();
1307 m_aTBPreview.SetTextColor( rStyleSettings.GetFieldTextColor() );
1308 m_aTBPreview.SetTextFillColor();
1310 SetBackground( rStyleSettings.GetFieldColor() );
1311 m_aBorder.SetBackground( rStyleSettings.GetFieldColor() );
1312 m_aFL.SetBackground( rStyleSettings.GetFieldColor() );
1313 m_aDocumentInfo.SetBackground( rStyleSettings.GetFieldColor() );
1314 m_aTBPreview.SetBackground( rStyleSettings.GetFieldColor() );
1315 m_pTablePreview->SetBackground( rStyleSettings.GetFieldColor() );
1317 // -----------------------------------------------------------------------------
1318 OPreviewWindow::OPreviewWindow(Window* _pParent)
1319 : Window(_pParent)
1321 ImplInitSettings( sal_True, sal_True, sal_True );
1323 // -----------------------------------------------------------------------------
1324 sal_Bool OPreviewWindow::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
1326 const Size aWinSize( GetOutputSizePixel() );
1327 Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
1328 sal_Bool bRet = sal_False;
1330 if( aNewSize.Width() && aNewSize.Height() )
1332 // scale to fit window
1333 const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
1334 const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
1336 if ( fGrfWH < fWinWH )
1338 aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
1339 aNewSize.Height()= aWinSize.Height();
1341 else
1343 aNewSize.Width() = aWinSize.Width();
1344 aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
1347 const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
1348 ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
1350 rResultRect = Rectangle( aNewPos, aNewSize );
1351 bRet = sal_True;
1354 return bRet;
1357 // ------------------------------------------------------------------------
1359 void OPreviewWindow::Paint( const Rectangle& rRect )
1361 Window::Paint( rRect );
1363 if( ImplGetGraphicCenterRect( m_aGraphicObj.GetGraphic(), m_aPreviewRect ) )
1365 const Point aPos( m_aPreviewRect.TopLeft() );
1366 const Size aSize( m_aPreviewRect.GetSize() );
1368 if( m_aGraphicObj.IsAnimated() )
1369 m_aGraphicObj.StartAnimation( this, aPos, aSize );
1370 else
1371 m_aGraphicObj.Draw( this, aPos, aSize );
1374 // -----------------------------------------------------------------------------
1375 void OPreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
1377 Window::DataChanged( rDCEvt );
1379 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1380 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1382 ImplInitSettings( sal_True, sal_True, sal_True );
1383 Invalidate();
1386 // -----------------------------------------------------------------------------
1387 void OPreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
1389 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1390 if( bFont )
1392 Font aFont;
1393 aFont = rStyleSettings.GetFieldFont();
1394 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1395 SetPointFont( aFont );
1398 if( bForeground || bFont )
1400 SetTextColor( rStyleSettings.GetFieldTextColor() );
1401 SetTextFillColor();
1404 if( bBackground )
1405 SetBackground( rStyleSettings.GetFieldColor() );
1407 // -----------------------------------------------------------------------------
1408 // -----------------------------------------------------------------------------
1410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */