update dev300-m58
[ooovba.git] / dbaccess / source / ui / app / AppDetailPageHelper.cxx
blob848ea0aaf9a698917c366d9b6eb5be0a298d1721
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AppDetailPageHelper.cxx,v $
10 * $Revision: 1.33.24.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_APPDETAILPAGEHELPER_HXX
34 #include "AppDetailPageHelper.hxx"
35 #endif
36 #ifndef _DBAUI_MODULE_DBU_HXX_
37 #include "moduledbu.hxx"
38 #endif
39 #ifndef _TOOLS_DEBUG_HXX
40 #include <tools/debug.hxx>
41 #endif
42 #ifndef TOOLS_DIAGNOSE_EX_H
43 #include <tools/diagnose_ex.h>
44 #endif
45 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
46 #include <connectivity/dbtools.hxx>
47 #endif
48 #ifndef _DBAUI_TABLETREE_HXX_
49 #include "tabletree.hxx"
50 #endif
51 #ifndef DBAUI_TOOLS_HXX
52 #include "UITools.hxx"
53 #endif
54 #ifndef DBAUI_DBTREELISTBOX_HXX
55 #include "dbtreelistbox.hxx"
56 #endif
57 #ifndef _COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
58 #include <com/sun/star/frame/XLayoutManager.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
61 #include <com/sun/star/beans/XPropertySet.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_AWT_XTABCONTROLLER_HPP_
64 #include <com/sun/star/awt/XTabController.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
67 #include <com/sun/star/sdbc/XConnection.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
70 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
71 #endif
72 #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
73 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
76 #include <com/sun/star/frame/XFrame.hpp>
77 #endif
78 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
79 #include <com/sun/star/frame/FrameSearchFlag.hpp>
80 #endif
81 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
82 #include <com/sun/star/frame/XComponentLoader.hpp>
83 #endif
84 #ifndef _COM_SUN_STAR_FRAME_XFRAMES_HPP_
85 #include <com/sun/star/frame/XFrames.hpp>
86 #endif
87 #ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPPLIER_HPP_
88 #include <com/sun/star/frame/XFramesSupplier.hpp>
89 #endif
90 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
91 #include <com/sun/star/awt/XWindow.hpp>
92 #endif
93 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
94 #include <toolkit/helper/vclunohelper.hxx>
95 #endif
96 #ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_
97 #include <com/sun/star/ucb/XContentCreator.hpp>
98 #endif
99 #ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_
100 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
101 #endif
102 #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
103 #include <com/sun/star/ucb/XCommandProcessor.hpp>
104 #endif
105 #ifndef _COM_SUN_STAR_UCB_COMMAND_HPP_
106 #include <com/sun/star/ucb/Command.hpp>
107 #endif
108 #ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_
109 #include <com/sun/star/form/XLoadable.hpp>
110 #endif
111 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
112 #include <com/sun/star/container/XChild.hpp>
113 #endif
114 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
115 #include <com/sun/star/container/XContainer.hpp>
116 #endif
117 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
118 #include <com/sun/star/sdb/CommandType.hpp>
119 #endif
120 #ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
121 #include <com/sun/star/util/XCloseable.hpp>
122 #endif
123 #ifndef _COM_SUN_STAR_SDB_APPLICATION_XDATABASEDOCUMENTUI_HPP_
124 #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
125 #endif
126 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
127 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
128 #ifndef DBAUI_APPVIEW_HXX
129 #include "AppView.hxx"
130 #endif
131 #ifndef _DBA_DBACCESS_HELPID_HRC_
132 #include "dbaccess_helpid.hrc"
133 #endif
134 #ifndef _DBU_APP_HRC_
135 #include "dbu_app.hrc"
136 #endif
137 #ifndef _DBACCESS_UI_CALLBACKS_HXX_
138 #include "callbacks.hxx"
139 #endif
140 #ifndef DBAUI_ICONTROLLER_HXX
141 #include "IController.hxx"
142 #endif
143 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
144 #include "dbustrings.hrc"
145 #endif
146 #ifndef _DBACCESS_SLOTID_HRC_
147 #include "dbaccess_slotid.hrc"
148 #endif
149 #ifndef DBACCESS_DATABASE_OBJECT_VIEW_HXX
150 #include "databaseobjectview.hxx"
151 #endif
152 #ifndef DBACCESS_IMAGEPROVIDER_HXX
153 #include "imageprovider.hxx"
154 #endif
155 #ifndef _SV_WAITOBJ_HXX
156 #include <vcl/waitobj.hxx>
157 #endif
158 #ifndef _STREAM_HXX
159 #include <tools/stream.hxx>
160 #endif
161 #ifndef _TOOLS_DEBUG_HXX
162 #include <tools/debug.hxx>
163 #endif
164 #ifndef _RTL_USTRBUF_HXX_
165 #include <rtl/ustrbuf.hxx>
166 #endif
167 #include "IApplicationController.hxx"
169 #include <com/sun/star/document/XDocumentProperties.hpp>
172 using namespace ::dbaui;
173 using namespace ::com::sun::star::container;
174 using namespace ::com::sun::star::uno;
175 using namespace ::com::sun::star::ucb;
176 using namespace ::com::sun::star::frame;
177 using namespace ::com::sun::star::form;
178 using namespace ::com::sun::star::sdb;
179 using namespace ::com::sun::star::sdb::application;
180 using namespace ::com::sun::star::sdbc;
181 using namespace ::com::sun::star::sdbcx;
182 using namespace ::com::sun::star::beans;
183 using namespace ::com::sun::star;
184 using ::com::sun::star::awt::XTabController;
186 namespace dbaui
188 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
189 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
192 namespace
194 SvLBoxEntry* lcl_findEntry_impl(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvLBoxEntry* _pFirst)
196 SvLBoxEntry* pReturn = NULL;
197 sal_Int32 nIndex = 0;
198 String sName( _rName.getToken(0,'/',nIndex) );
200 SvLBoxEntry* pEntry = _pFirst;
201 while( pEntry )
203 if ( rTree.GetEntryText(pEntry) == sName )
205 if ( nIndex != -1 )
207 sName = _rName.getToken(0,'/',nIndex);
208 pEntry = rTree.FirstChild(pEntry);
210 else
212 pReturn = pEntry;
213 break;
216 else
217 pEntry = rTree.NextSibling(pEntry);
219 return pReturn;
221 SvLBoxEntry* lcl_findEntry(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvLBoxEntry* _pFirst)
223 sal_Int32 nIndex = 0;
224 ::rtl::OUString sErase = _rName.getToken(0,'/',nIndex); // we don't want to have the "private:forms" part
225 return (nIndex != -1 ? lcl_findEntry_impl(rTree,_rName.copy(sErase.getLength() + 1),_pFirst) : NULL);
227 //==================================================================
228 // class OPreviewWindow
229 //==================================================================
230 class OTablePreviewWindow : public Window
232 DECL_LINK(OnDisableInput, void*);
233 void ImplInitSettings( BOOL bFont, BOOL bForeground, BOOL bBackground );
234 protected:
235 virtual void DataChanged(const DataChangedEvent& rDCEvt);
236 public:
237 OTablePreviewWindow( Window* pParent, WinBits nStyle = 0 );
238 virtual long Notify( NotifyEvent& rNEvt );
240 // -----------------------------------------------------------------------------
241 OTablePreviewWindow::OTablePreviewWindow(Window* pParent, WinBits nStyle) : Window( pParent, nStyle)
243 ImplInitSettings( sal_True, sal_True, sal_True );
245 // -----------------------------------------------------------------------------
246 long OTablePreviewWindow::Notify( NotifyEvent& rNEvt )
248 long nRet = Window::Notify( rNEvt );
249 if ( rNEvt.GetType() == EVENT_INPUTENABLE && IsInputEnabled() )
250 PostUserEvent( LINK( this, OTablePreviewWindow, OnDisableInput) );
251 return nRet;
253 // -----------------------------------------------------------------------------
254 IMPL_LINK(OTablePreviewWindow, OnDisableInput, void*, EMPTYARG)
256 EnableInput(FALSE);
257 return 0L;
259 // -----------------------------------------------------------------------------
260 void OTablePreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
262 Window::DataChanged( rDCEvt );
264 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
265 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
267 ImplInitSettings( sal_True, sal_True, sal_True );
268 Invalidate();
271 // -----------------------------------------------------------------------------
272 void OTablePreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
274 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
275 if( bFont )
277 Font aFont;
278 aFont = rStyleSettings.GetFieldFont();
279 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
280 SetPointFont( aFont );
283 if( bForeground || bFont )
285 SetTextColor( rStyleSettings.GetFieldTextColor() );
286 SetTextFillColor();
287 } // if( bForeground || bFont )
289 if( bBackground )
290 SetBackground( rStyleSettings.GetFieldColor() );
294 //==================================================================
295 // class OAppDetailPageHelper
296 DBG_NAME(OAppDetailPageHelper)
297 //==================================================================
298 OAppDetailPageHelper::OAppDetailPageHelper(Window* _pParent,OAppBorderWindow& _rBorderWin,PreviewMode _ePreviewMode) : Window(_pParent,WB_DIALOGCONTROL)
299 ,m_rBorderWin(_rBorderWin)
300 ,m_aFL(this,WB_VERT)
301 ,m_aTBPreview(this,WB_TABSTOP )
302 ,m_aBorder(this,WB_BORDER | WB_READONLY)
303 ,m_aPreview(&m_aBorder)
304 ,m_aDocumentInfo(&m_aBorder,WB_LEFT | WB_VSCROLL | WB_READONLY )
305 ,m_pTablePreview(NULL)
306 ,m_ePreviewMode(_ePreviewMode)
308 DBG_CTOR(OAppDetailPageHelper,NULL);
310 m_aBorder.SetBorderStyle(WINDOW_BORDER_MONO);
312 m_aMenu.reset(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
314 m_aTBPreview.SetOutStyle(TOOLBOX_STYLE_FLAT);
315 m_aTBPreview.InsertItem(SID_DB_APP_DISABLE_PREVIEW,m_aMenu->GetItemText(SID_DB_APP_DISABLE_PREVIEW),TIB_LEFT|TIB_DROPDOWN|TIB_AUTOSIZE|TIB_RADIOCHECK);
316 m_aTBPreview.SetHelpId(HID_APP_VIEW_PREVIEW_CB);
317 m_aTBPreview.SetDropdownClickHdl( LINK( this, OAppDetailPageHelper, OnDropdownClickHdl ) );
318 m_aTBPreview.EnableMenuStrings();
319 m_aTBPreview.Enable(TRUE);
321 m_aBorder.SetUniqueId(UID_APP_VIEW_PREVIEW_1);
323 m_aPreview.SetHelpId(HID_APP_VIEW_PREVIEW_1);
325 m_pTablePreview = new OTablePreviewWindow(&m_aBorder,WB_READONLY | WB_DIALOGCONTROL );
326 m_pTablePreview->SetHelpId(HID_APP_VIEW_PREVIEW_2);
328 m_aDocumentInfo.SetHelpId(HID_APP_VIEW_PREVIEW_3);
330 m_xWindow = VCLUnoHelper::GetInterface( m_pTablePreview );
332 SetUniqueId(UID_APP_DETAILPAGE_HELPER);
333 for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
334 m_pLists[i] = NULL;
335 ImplInitSettings();
337 // -----------------------------------------------------------------------------
338 OAppDetailPageHelper::~OAppDetailPageHelper()
342 Reference< ::util::XCloseable> xCloseable(m_xFrame,UNO_QUERY);
343 if ( xCloseable.is() )
344 xCloseable->close(sal_True);
346 catch(Exception)
348 OSL_ENSURE(0,"Exception thrown while disposing preview frame!");
351 for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
353 if ( m_pLists[i] )
355 m_pLists[i]->clearCurrentSelection();
356 m_pLists[i]->Hide();
357 ::std::auto_ptr<DBTreeListBox> aTemp(m_pLists[i]);
358 m_pLists[i]->clearCurrentSelection(); // why a second time?
359 m_pLists[i] = NULL;
364 DBG_DTOR(OAppDetailPageHelper,NULL);
366 // -----------------------------------------------------------------------------
367 int OAppDetailPageHelper::getVisibleControlIndex() const
369 int i = 0;
370 for (; i < E_ELEMENT_TYPE_COUNT ; ++i)
372 if ( m_pLists[i] && m_pLists[i]->IsVisible() )
373 break;
375 return i;
377 // -----------------------------------------------------------------------------
378 void OAppDetailPageHelper::selectAll()
380 int nPos = getVisibleControlIndex();
381 if ( nPos < E_ELEMENT_TYPE_COUNT )
383 m_pLists[nPos]->SelectAll(TRUE);
386 // -----------------------------------------------------------------------------
387 void OAppDetailPageHelper::sort(int _nPos,SvSortMode _eSortMode )
389 OSL_ENSURE(m_pLists[_nPos],"List can not be NULL! ->GPF");
390 SvLBoxTreeList* pModel = m_pLists[_nPos]->GetModel();
391 SvSortMode eOldSortMode = pModel->GetSortMode();
392 pModel->SetSortMode(_eSortMode);
393 if ( eOldSortMode != _eSortMode )
394 pModel->Resort();
396 // -----------------------------------------------------------------------------
397 sal_Bool OAppDetailPageHelper::isSortUp() const
399 SvSortMode eSortMode = SortNone;
400 int nPos = getVisibleControlIndex();
401 if ( nPos < E_ELEMENT_TYPE_COUNT )
403 SvLBoxTreeList* pModel = m_pLists[nPos]->GetModel();
404 eSortMode = pModel->GetSortMode();
406 return eSortMode == SortAscending;
408 // -----------------------------------------------------------------------------
409 void OAppDetailPageHelper::sortDown()
411 int nPos = getVisibleControlIndex();
412 if ( nPos < E_ELEMENT_TYPE_COUNT )
413 sort(nPos,SortDescending);
415 // -----------------------------------------------------------------------------
416 void OAppDetailPageHelper::sortUp()
418 int nPos = getVisibleControlIndex();
419 if ( nPos < E_ELEMENT_TYPE_COUNT )
420 sort(nPos,SortAscending);
422 // -----------------------------------------------------------------------------
423 void OAppDetailPageHelper::getSelectionElementNames( ::std::vector< ::rtl::OUString>& _rNames ) const
425 int nPos = getVisibleControlIndex();
426 if ( nPos < E_ELEMENT_TYPE_COUNT )
428 DBTreeListBox& rTree = *m_pLists[nPos];
429 sal_Int32 nCount = rTree.GetEntryCount();
430 _rNames.reserve(nCount);
431 SvLBoxEntry* pEntry = rTree.FirstSelected();
432 ElementType eType = getElementType();
433 while( pEntry )
435 if ( eType == E_TABLE )
437 if( rTree.GetChildCount(pEntry) == 0 )
438 _rNames.push_back( getQualifiedName( pEntry ) );
440 else
442 ::rtl::OUString sName = rTree.GetEntryText(pEntry);
443 SvLBoxEntry* pParent = rTree.GetParent(pEntry);
444 while(pParent)
446 sName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
447 pParent = rTree.GetParent(pParent);
449 _rNames.push_back(sName);
451 pEntry = rTree.NextSelected(pEntry);
456 // -----------------------------------------------------------------------------
457 void OAppDetailPageHelper::describeCurrentSelectionForControl( const Control& _rControl, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
459 enum ElementType eType = E_TABLE;
460 for ( size_t i=0; i < E_ELEMENT_TYPE_COUNT; eType = static_cast< ElementType >( ++i ) )
462 if ( m_pLists[eType] == &_rControl )
464 describeCurrentSelectionForType( eType, _out_rSelectedObjects );
465 return;
468 OSL_ENSURE( false, "OAppDetailPageHelper::describeCurrentSelectionForControl: invalid control!" );
471 // -----------------------------------------------------------------------------
472 void OAppDetailPageHelper::describeCurrentSelectionForType( const ElementType _eType, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
474 OSL_ENSURE( _eType < E_ELEMENT_TYPE_COUNT, "OAppDetailPageHelper::describeCurrentSelectionForType: invalid type!" );
475 DBTreeListBox* pList = ( _eType < E_ELEMENT_TYPE_COUNT ) ? m_pLists[ _eType ] : NULL;
476 OSL_ENSURE( pList, "OAppDetailPageHelper::describeCurrentSelectionForType: "
477 "You really should ensure this type has already been viewed before!" );
478 if ( !pList )
479 return;
481 ::std::vector< NamedDatabaseObject > aSelected;
483 SvLBoxEntry* pEntry = pList->FirstSelected();
484 while( pEntry )
486 NamedDatabaseObject aObject;
487 switch ( _eType )
489 case E_TABLE:
491 OTableTreeListBox& rTableTree = dynamic_cast< OTableTreeListBox& >( *pList );
492 aObject = rTableTree.describeObject( pEntry );
494 break;
495 case E_QUERY:
496 aObject.Type = DatabaseObject::QUERY;
497 aObject.Name = pList->GetEntryText( pEntry );
498 break;
500 case E_FORM:
501 case E_REPORT:
503 ::rtl::OUString sName = pList->GetEntryText(pEntry);
504 SvLBoxEntry* pParent = pList->GetParent(pEntry);
505 while ( pParent )
507 ::rtl::OUStringBuffer buffer;
508 buffer.append( pList->GetEntryText( pParent ) );
509 buffer.append( sal_Unicode( '/' ) );
510 buffer.append( sName );
511 sName = buffer.makeStringAndClear();
513 pParent = pList->GetParent( pParent );
516 if ( isLeaf( pEntry ) )
517 aObject.Type = ( _eType == E_FORM ) ? DatabaseObject::FORM : DatabaseObject::REPORT;
518 else
519 aObject.Type = ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER : DatabaseObjectContainer::REPORTS_FOLDER;
520 aObject.Name = sName;
522 break;
523 default:
524 OSL_ENSURE( false, "OAppDetailPageHelper::describeCurrentSelectionForType: unexpected type!" );
525 break;
528 if ( aObject.Name.getLength() )
530 aSelected.push_back( aObject );
533 pEntry = pList->NextSelected(pEntry);
536 _out_rSelectedObjects.realloc( aSelected.size() );
537 ::std::copy( aSelected.begin(), aSelected.end(), _out_rSelectedObjects.getArray() );
540 // -----------------------------------------------------------------------------
541 void OAppDetailPageHelper::selectElements(const Sequence< ::rtl::OUString>& _aNames)
543 int nPos = getVisibleControlIndex();
544 if ( nPos < E_ELEMENT_TYPE_COUNT )
546 DBTreeListBox& rTree = *m_pLists[nPos];
547 rTree.SelectAll(FALSE);
548 const ::rtl::OUString* pIter = _aNames.getConstArray();
549 const ::rtl::OUString* pEnd = pIter + _aNames.getLength();
550 for(;pIter != pEnd;++pIter)
552 SvLBoxEntry* pEntry = rTree.GetEntryPosByName(*pIter);
553 if ( pEntry )
554 rTree.Select(pEntry);
558 // -----------------------------------------------------------------------------
559 ::rtl::OUString OAppDetailPageHelper::getQualifiedName( SvLBoxEntry* _pEntry ) const
561 int nPos = getVisibleControlIndex();
562 ::rtl::OUString sComposedName;
564 if ( nPos >= E_ELEMENT_TYPE_COUNT )
565 return sComposedName;
567 OSL_ENSURE(m_pLists[nPos],"Tables tree view is NULL! -> GPF");
568 DBTreeListBox& rTree = *m_pLists[nPos];
570 SvLBoxEntry* pEntry = _pEntry;
571 if ( !pEntry )
572 pEntry = rTree.FirstSelected();
574 if ( !pEntry )
575 return sComposedName;
577 if ( getElementType() == E_TABLE )
579 const OTableTreeListBox& rTreeView = dynamic_cast< const OTableTreeListBox& >( *m_pLists[nPos] );
580 sComposedName = rTreeView.getQualifiedTableName( pEntry );
582 else
584 sComposedName = rTree.GetEntryText(pEntry);
585 SvLBoxEntry* pParent = rTree.GetParent(pEntry);
586 while(pParent)
588 sComposedName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sComposedName;
589 pParent = rTree.GetParent(pParent);
593 return sComposedName;
595 // -----------------------------------------------------------------------------
596 ElementType OAppDetailPageHelper::getElementType() const
598 int nPos = getVisibleControlIndex();
599 return static_cast<ElementType>(nPos);
601 // -----------------------------------------------------------------------------
602 sal_Int32 OAppDetailPageHelper::getSelectionCount()
604 sal_Int32 nCount = 0;
605 int nPos = getVisibleControlIndex();
606 if ( nPos < E_ELEMENT_TYPE_COUNT )
608 DBTreeListBox& rTree = *m_pLists[nPos];
609 SvLBoxEntry* pEntry = rTree.FirstSelected();
610 while( pEntry )
612 ++nCount;
613 pEntry = rTree.NextSelected(pEntry);
616 return nCount;
618 // -----------------------------------------------------------------------------
619 sal_Int32 OAppDetailPageHelper::getElementCount()
621 sal_Int32 nCount = 0;
622 int nPos = getVisibleControlIndex();
623 if ( nPos < E_ELEMENT_TYPE_COUNT )
625 nCount = m_pLists[nPos]->GetEntryCount();
627 return nCount;
629 // -----------------------------------------------------------------------------
630 sal_Bool OAppDetailPageHelper::isCutAllowed()
632 return sal_False;
634 // -----------------------------------------------------------------------------
635 sal_Bool OAppDetailPageHelper::isCopyAllowed()
637 // int nPos = getVisibleControlIndex();
638 return sal_True;
640 // -----------------------------------------------------------------------------
641 sal_Bool OAppDetailPageHelper::isPasteAllowed()
643 // int nPos = getVisibleControlIndex();
644 return sal_True;
646 // -----------------------------------------------------------------------------
647 void OAppDetailPageHelper::copy()
650 // -----------------------------------------------------------------------------
651 void OAppDetailPageHelper::cut()
654 // -----------------------------------------------------------------------------
655 void OAppDetailPageHelper::paste()
658 // -----------------------------------------------------------------------------
659 bool OAppDetailPageHelper::isLeaf(SvLBoxEntry* _pEntry) const
661 sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() );
662 if ( ( nEntryType == DatabaseObjectContainer::TABLES )
663 || ( nEntryType == DatabaseObjectContainer::CATALOG )
664 || ( nEntryType == DatabaseObjectContainer::SCHEMA )
665 || ( nEntryType == DatabaseObjectContainer::FORMS_FOLDER )
666 || ( nEntryType == DatabaseObjectContainer::REPORTS_FOLDER )
668 return false;
670 return true;
673 // -----------------------------------------------------------------------------
674 sal_Bool OAppDetailPageHelper::isALeafSelected() const
676 int nPos = getVisibleControlIndex();
677 sal_Bool bLeafSelected = sal_False;
678 if ( nPos < E_ELEMENT_TYPE_COUNT )
680 DBTreeListBox& rTree = *m_pLists[nPos];
681 SvLBoxEntry* pEntry = rTree.FirstSelected( );
682 while( !bLeafSelected && pEntry )
684 bLeafSelected = isLeaf( pEntry );
685 pEntry = rTree.NextSelected(pEntry);
688 return bLeafSelected;
690 // -----------------------------------------------------------------------------
691 SvLBoxEntry* OAppDetailPageHelper::getEntry( const Point& _aPosPixel) const
693 SvLBoxEntry* pReturn = NULL;
694 int nPos = getVisibleControlIndex();
695 if ( nPos < E_ELEMENT_TYPE_COUNT )
696 pReturn = m_pLists[nPos]->GetEntry( _aPosPixel,TRUE );
697 return pReturn;
699 // -----------------------------------------------------------------------------
700 void OAppDetailPageHelper::createTablesPage(const Reference< XConnection>& _xConnection)
702 OSL_ENSURE(_xConnection.is(),"Connection is NULL! -> GPF");
704 if ( !m_pLists[E_TABLE] )
706 OTableTreeListBox* pTreeView = new OTableTreeListBox(this
707 ,getBorderWin().getView()->getORB()
708 ,WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP
709 ,sal_False);
710 pTreeView->SetHelpId(HID_APP_TABLE_TREE);
711 m_pLists[E_TABLE] = pTreeView;
713 ImageProvider aImageProvider( _xConnection );
714 createTree( pTreeView,
715 aImageProvider.getDefaultImage( DatabaseObject::TABLE, false ),
716 aImageProvider.getDefaultImage( DatabaseObject::TABLE, true )
719 pTreeView->notifyHiContrastChanged();
720 m_aBorder.SetZOrder(pTreeView, WINDOW_ZORDER_BEHIND);
722 if ( !m_pLists[E_TABLE]->GetEntryCount() )
724 static_cast<OTableTreeListBox*>(m_pLists[E_TABLE])->UpdateTableList(_xConnection);
726 SvLBoxEntry* pEntry = m_pLists[E_TABLE]->First();
727 if ( pEntry )
728 m_pLists[E_TABLE]->Expand(pEntry);
729 m_pLists[E_TABLE]->SelectAll(FALSE);
732 setDetailPage(m_pLists[E_TABLE]);
735 // -----------------------------------------------------------------------------
736 void OAppDetailPageHelper::getElementIcons( ElementType _eType, USHORT& _rImageId, USHORT& _rHighContrastImageId )
738 ImageProvider aImageProvider;
739 _rImageId = _rHighContrastImageId = 0;
741 sal_Int32 nDatabaseObjectType( 0 );
742 switch(_eType )
744 case E_FORM: nDatabaseObjectType = DatabaseObject::FORM; break;
745 case E_REPORT: nDatabaseObjectType = DatabaseObject::REPORT; break;
746 case E_QUERY: nDatabaseObjectType = DatabaseObject::QUERY; break;
747 default:
748 OSL_ENSURE( sal_False, "OAppDetailPageHelper::GetElementIcons: invalid element type!" );
749 return;
751 _rImageId = aImageProvider.getDefaultImageResourceID( nDatabaseObjectType, false );
752 _rHighContrastImageId = aImageProvider.getDefaultImageResourceID( nDatabaseObjectType, true );
755 // -----------------------------------------------------------------------------
756 void OAppDetailPageHelper::createPage(ElementType _eType,const Reference< XNameAccess >& _xContainer)
758 OSL_ENSURE(E_TABLE != _eType,"E_TABLE isn't allowed.");
760 USHORT nHelpId = 0, nImageId = 0, nImageIdH = 0;
761 ImageProvider aImageProvider;
762 Image aFolderImage, aFolderImageHC;
763 switch( _eType )
765 case E_FORM:
766 nHelpId = HID_APP_FORM_TREE;
767 aFolderImage = aImageProvider.getFolderImage( DatabaseObject::FORM, false );
768 aFolderImageHC = aImageProvider.getFolderImage( DatabaseObject::FORM, true );
769 break;
770 case E_REPORT:
771 nHelpId = HID_APP_REPORT_TREE;
772 aFolderImage = aImageProvider.getFolderImage( DatabaseObject::REPORT, false );
773 aFolderImageHC = aImageProvider.getFolderImage( DatabaseObject::REPORT, true );
774 break;
775 case E_QUERY:
776 nHelpId = HID_APP_QUERY_TREE;
777 aFolderImage = aImageProvider.getFolderImage( DatabaseObject::QUERY, false );
778 aFolderImageHC = aImageProvider.getFolderImage( DatabaseObject::QUERY, true );
779 break;
780 default:
781 OSL_ENSURE(0,"Illegal call!");
783 getElementIcons( _eType, nImageId, nImageIdH );
785 if ( !m_pLists[_eType] )
787 m_pLists[_eType] = createSimpleTree( nHelpId, aFolderImage, aFolderImageHC );
790 if ( m_pLists[_eType] )
792 if ( !m_pLists[_eType]->GetEntryCount() && _xContainer.is() )
794 fillNames( _xContainer, _eType, nImageId, nImageIdH, NULL );
796 m_pLists[_eType]->SelectAll(FALSE);
798 setDetailPage(m_pLists[_eType]);
801 // -----------------------------------------------------------------------------
802 void OAppDetailPageHelper::setDetailPage(Window* _pWindow)
804 OSL_ENSURE(_pWindow,"OAppDetailPageHelper::setDetailPage: Window is NULL!");
805 Window* pCurrent = getCurrentView();
806 if ( pCurrent )
807 pCurrent->Hide();
809 showPreview(NULL);
810 BOOL bHasFocus = FALSE;
811 m_aFL.Show();
813 bHasFocus = pCurrent->HasChildPathFocus();
814 _pWindow->Show();
816 m_aTBPreview.Show();
817 m_aBorder.Show();
818 switchPreview(m_ePreviewMode,TRUE);
820 if ( bHasFocus )
821 _pWindow->GrabFocus();
822 Resize();
825 // -----------------------------------------------------------------------------
826 namespace
828 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
829 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
831 static sal_Int32 lcl_getFolderIndicatorForType( const ElementType _eType )
833 const sal_Int32 nFolderIndicator =
834 ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER
835 : ( _eType == E_REPORT ) ? DatabaseObjectContainer::REPORTS_FOLDER : -1;
836 return nFolderIndicator;
840 // -----------------------------------------------------------------------------
841 void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, const ElementType _eType,
842 const USHORT _nImageId, const USHORT _nHighContrastImageId, SvLBoxEntry* _pParent )
844 OSL_ENSURE(_xContainer.is(),"Data source is NULL! -> GPF");
845 OSL_ENSURE( ( _eType >= E_TABLE ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OAppDetailPageHelper::fillNames: invalid type!" );
847 DBTreeListBox* pList = m_pLists[ _eType ];
848 OSL_ENSURE( pList, "OAppDetailPageHelper::fillNames: you really should create the list before calling this!" );
849 if ( !pList )
850 return;
852 if ( _xContainer.is() && _xContainer->hasElements() )
854 const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
856 Sequence< ::rtl::OUString> aSeq = _xContainer->getElementNames();
857 const ::rtl::OUString* pIter = aSeq.getConstArray();
858 const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
859 for(;pIter != pEnd;++pIter)
861 SvLBoxEntry* pEntry = NULL;
862 Reference<XNameAccess> xSubElements(_xContainer->getByName(*pIter),UNO_QUERY);
863 if ( xSubElements.is() )
865 pEntry = pList->InsertEntry( *pIter, _pParent, FALSE, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
866 getBorderWin().getView()->getAppController().containerFound( Reference< XContainer >( xSubElements, UNO_QUERY ) );
867 fillNames( xSubElements, _eType, _nImageId, _nHighContrastImageId, pEntry );
869 else
871 pEntry = pList->InsertEntry( *pIter, _pParent );
873 Image aImage = Image( ModuleRes( _nImageId ) );
874 pList->SetExpandedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL );
875 pList->SetCollapsedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL );
877 Image aHCImage = Image( ModuleRes( _nHighContrastImageId ) );
878 pList->SetExpandedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST );
879 pList->SetCollapsedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST );
884 // -----------------------------------------------------------------------------
885 DBTreeListBox* OAppDetailPageHelper::createSimpleTree( ULONG _nHelpId, const Image& _rImage, const Image& _rImageHC )
887 DBTreeListBox* pTreeView = new DBTreeListBox(this,getBorderWin().getView()->getORB(),WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
888 pTreeView->SetHelpId(_nHelpId);
889 return createTree( pTreeView, _rImage, _rImageHC );
892 // -----------------------------------------------------------------------------
893 DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, const Image& _rImage, const Image& _rImageHC )
895 WaitObject aWaitCursor(this);
897 _pTreeView->SetWindowBits(WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
898 _pTreeView->GetModel()->SetSortMode(SortAscending);
899 _pTreeView->EnableCheckButton( NULL ); // do not show any buttons
900 _pTreeView->SetSelectionMode(MULTIPLE_SELECTION);
902 _pTreeView->SetDefaultCollapsedEntryBmp( _rImage );
903 _pTreeView->SetDefaultCollapsedEntryBmp( _rImageHC, BMP_COLOR_HIGHCONTRAST );
904 _pTreeView->SetDefaultExpandedEntryBmp( _rImage );
905 _pTreeView->SetDefaultExpandedEntryBmp( _rImageHC, BMP_COLOR_HIGHCONTRAST );
907 _pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
908 _pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
909 _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
911 _pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
912 _pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
913 _pTreeView->setPasteHandler(LINK(this, OAppDetailPageHelper, OnPasteEntry));
914 _pTreeView->setDeleteHandler(LINK(this, OAppDetailPageHelper, OnDeleteEntry));
916 _pTreeView->setControlActionListener( &getBorderWin().getView()->getAppController() );
917 _pTreeView->setContextMenuProvider( &getBorderWin().getView()->getAppController() );
919 return _pTreeView;
921 // -----------------------------------------------------------------------------
922 void OAppDetailPageHelper::clearPages()
924 showPreview(NULL);
925 for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
927 if ( m_pLists[i] )
928 m_pLists[i]->Clear();
931 // -----------------------------------------------------------------------------
932 sal_Bool OAppDetailPageHelper::isFilled() const
934 size_t i = 0;
935 for (; i < E_ELEMENT_TYPE_COUNT && !m_pLists[i]; ++i)
937 return i != E_ELEMENT_TYPE_COUNT;
939 // -----------------------------------------------------------------------------
940 void OAppDetailPageHelper::elementReplaced(ElementType _eType
941 ,const ::rtl::OUString& _rOldName
942 ,const ::rtl::OUString& _rNewName )
944 DBTreeListBox* pTreeView = getCurrentView();
945 if ( pTreeView )
947 ::rtl::OUString sNewName = _rNewName;
948 SvLBoxEntry* pEntry = NULL;
949 switch( _eType )
951 case E_TABLE:
952 static_cast<OTableTreeListBox*>(pTreeView)->removedTable( _rOldName );
953 static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rNewName );
954 return;
956 case E_QUERY:
957 pEntry = lcl_findEntry_impl(*pTreeView,_rOldName,pTreeView->First());
958 break;
959 case E_FORM:
960 case E_REPORT:
961 pEntry = lcl_findEntry(*pTreeView,_rOldName,pTreeView->First());
962 break;
963 default:
964 OSL_ENSURE(0,"Invalid element type");
966 OSL_ENSURE(pEntry,"Do you know that the name isn't existence!");
967 if ( pEntry )
969 pTreeView->SetEntryText(pEntry,sNewName);
973 // -----------------------------------------------------------------------------
974 SvLBoxEntry* OAppDetailPageHelper::elementAdded(ElementType _eType,const ::rtl::OUString& _rName, const Any& _rObject )
976 SvLBoxEntry* pRet = NULL;
977 DBTreeListBox* pTreeView = m_pLists[_eType];
978 if( _eType == E_TABLE && pTreeView )
980 pRet = static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rName );
982 else if ( pTreeView )
985 SvLBoxEntry* pEntry = NULL;
986 Reference<XChild> xChild(_rObject,UNO_QUERY);
987 if ( xChild.is() && E_QUERY != _eType )
989 Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
990 if ( xContent.is() )
992 ::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
993 pEntry = lcl_findEntry(*pTreeView,sName,pTreeView->First());
997 USHORT nImageId = 0, nImageIdH = 0;
998 getElementIcons( _eType, nImageId, nImageIdH );
999 Reference<XNameAccess> xContainer(_rObject,UNO_QUERY);
1000 if ( xContainer.is() )
1002 const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
1003 pRet = pTreeView->InsertEntry( _rName, pEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
1004 fillNames( xContainer, _eType, nImageId, nImageIdH, pRet );
1006 else
1008 pRet = pTreeView->InsertEntry( _rName, pEntry );
1010 Image aImage = Image( ModuleRes( nImageId ) );
1011 pTreeView->SetExpandedEntryBmp( pRet, aImage, BMP_COLOR_NORMAL );
1012 pTreeView->SetCollapsedEntryBmp( pRet, aImage, BMP_COLOR_NORMAL );
1014 Image aHCImage = Image( ModuleRes( nImageIdH ) );
1015 pTreeView->SetExpandedEntryBmp( pRet, aHCImage, BMP_COLOR_HIGHCONTRAST );
1016 pTreeView->SetCollapsedEntryBmp( pRet, aHCImage, BMP_COLOR_HIGHCONTRAST );
1019 return pRet;
1021 // -----------------------------------------------------------------------------
1022 void OAppDetailPageHelper::elementRemoved( ElementType _eType,const ::rtl::OUString& _rName )
1024 DBTreeListBox* pTreeView = getCurrentView();
1025 if ( pTreeView )
1027 switch( _eType )
1029 case E_TABLE:
1030 // we don't need to clear the table here, it is already done by the dispose listener
1031 static_cast< OTableTreeListBox* >( pTreeView )->removedTable( _rName );
1032 break;
1033 case E_QUERY:
1034 if ( pTreeView )
1036 SvLBoxEntry* pEntry = lcl_findEntry_impl(*pTreeView,_rName,pTreeView->First());
1037 if ( pEntry )
1038 pTreeView->GetModel()->Remove(pEntry);
1040 break;
1041 case E_FORM:
1042 case E_REPORT:
1044 if ( pTreeView )
1046 SvLBoxEntry* pEntry = lcl_findEntry(*pTreeView,_rName,pTreeView->First());
1047 if ( pEntry )
1048 pTreeView->GetModel()->Remove(pEntry);
1051 break;
1052 default:
1053 OSL_ENSURE(0,"Invalid element type");
1055 if ( !pTreeView->GetEntryCount() )
1056 showPreview(NULL);
1059 // -----------------------------------------------------------------------------
1060 IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
1062 OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnEntryDoubleClick: invalid callback!" );
1063 bool bHandled = ( _pTree != NULL ) && getBorderWin().getView()->getAppController().onEntryDoubleClick( *_pTree );
1064 return bHandled ? 1L : 0L;
1066 // -----------------------------------------------------------------------------
1067 IMPL_LINK(OAppDetailPageHelper, OnEntrySelChange, void*, /*NOINTERESTEDIN*/)
1069 getBorderWin().getView()->getAppController().onSelectionChanged();
1070 return 1L;
1072 // -----------------------------------------------------------------------------
1073 IMPL_LINK( OAppDetailPageHelper, OnCutEntry, void*, /*NOINTERESTEDIN*/ )
1075 getBorderWin().getView()->getAppController().onCutEntry();
1076 return 1L;
1078 // -----------------------------------------------------------------------------
1079 IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, void*, /*NOINTERESTEDIN*/ )
1081 getBorderWin().getView()->getAppController().onCopyEntry();
1082 return 1L;
1084 // -----------------------------------------------------------------------------
1085 IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, void*, /*NOINTERESTEDIN*/ )
1087 getBorderWin().getView()->getAppController().onPasteEntry();
1088 return 1L;
1090 // -----------------------------------------------------------------------------
1091 IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, void*, /*NOINTERESTEDIN*/ )
1093 getBorderWin().getView()->getAppController().onDeleteEntry();
1094 return 1L;
1096 // -----------------------------------------------------------------------------
1097 void OAppDetailPageHelper::Resize()
1099 //////////////////////////////////////////////////////////////////////
1100 // Abmessungen parent window
1101 Size aOutputSize( GetOutputSize() );
1102 long nOutputWidth = aOutputSize.Width();
1103 long nOutputHeight = aOutputSize.Height();
1105 Window* pWindow = getCurrentView();
1106 if ( pWindow )
1108 Size aFLSize = LogicToPixel( Size( 2, 6 ), MAP_APPFONT );
1109 sal_Int32 n6PPT = aFLSize.Height();
1110 long nHalfOutputWidth = static_cast<long>(nOutputWidth * 0.5);
1112 pWindow->SetPosSizePixel( Point(0, 0), Size(nHalfOutputWidth - n6PPT, nOutputHeight) );
1114 m_aFL.SetPosSizePixel( Point(nHalfOutputWidth , 0 ), Size(aFLSize.Width(), nOutputHeight ) );
1116 String sText = m_aTBPreview.GetItemText(SID_DB_APP_DISABLE_PREVIEW);
1117 Size aTBSize = m_aTBPreview.CalcWindowSizePixel();
1118 m_aTBPreview.SetPosSizePixel( Point(nOutputWidth - aTBSize.getWidth(), 0 ),
1119 aTBSize );
1121 m_aBorder.SetPosSizePixel( Point(nHalfOutputWidth + aFLSize.Width() + n6PPT, aTBSize.getHeight() + n6PPT ),
1122 Size(nHalfOutputWidth - aFLSize.Width() - n6PPT, nOutputHeight - 2*n6PPT - aTBSize.getHeight()) );
1123 m_aPreview.SetPosSizePixel( Point(0,0),m_aBorder.GetSizePixel() );
1124 m_aDocumentInfo.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1125 m_pTablePreview->SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1128 // -----------------------------------------------------------------------------
1129 PreviewMode OAppDetailPageHelper::getPreviewMode()
1131 return m_ePreviewMode;
1133 // -----------------------------------------------------------------------------
1134 sal_Bool OAppDetailPageHelper::isPreviewEnabled()
1136 return m_ePreviewMode != E_PREVIEWNONE;
1138 // -----------------------------------------------------------------------------
1139 void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,BOOL _bForce)
1141 if ( m_ePreviewMode != _eMode || _bForce )
1143 m_ePreviewMode = _eMode;
1145 getBorderWin().getView()->getAppController().previewChanged(static_cast<sal_Int32>(m_ePreviewMode));
1147 sal_uInt16 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1148 switch ( m_ePreviewMode )
1150 case E_PREVIEWNONE:
1151 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1152 break;
1153 case E_DOCUMENT:
1154 nSelectedAction = SID_DB_APP_VIEW_DOC_PREVIEW;
1155 break;
1156 case E_DOCUMENTINFO:
1157 if ( getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) )
1158 nSelectedAction = SID_DB_APP_VIEW_DOCINFO_PREVIEW;
1159 else
1160 m_ePreviewMode = E_PREVIEWNONE;
1161 break;
1164 m_aMenu->CheckItem(nSelectedAction);
1165 m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
1166 Resize();
1168 // simulate a selectionChanged event at the controller, to force the preview to be updated
1169 if ( isPreviewEnabled() )
1171 if ( getCurrentView() && getCurrentView()->FirstSelected() )
1173 getBorderWin().getView()->getAppController().onSelectionChanged();
1176 else
1178 m_pTablePreview->Hide();
1179 m_aPreview.Hide();
1180 m_aDocumentInfo.Hide();
1184 // -----------------------------------------------------------------------------
1185 void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
1187 if ( isPreviewEnabled() )
1189 m_pTablePreview->Hide();
1191 WaitObject aWaitCursor( this );
1194 Reference<XCommandProcessor> xContent(_xContent,UNO_QUERY);
1195 if ( xContent.is() )
1197 com::sun::star::ucb::Command aCommand;
1198 if ( m_ePreviewMode == E_DOCUMENT )
1199 aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("preview"));
1200 else
1201 aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getDocumentInfo"));
1203 Any aPreview = xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
1204 if ( m_ePreviewMode == E_DOCUMENT )
1206 m_aDocumentInfo.Hide();
1207 m_aPreview.Show();
1209 Graphic aGraphic;
1210 Sequence < sal_Int8 > aBmpSequence;
1211 if ( aPreview >>= aBmpSequence )
1213 SvMemoryStream aData( aBmpSequence.getArray(),
1214 aBmpSequence.getLength(),
1215 STREAM_READ );
1217 GraphicConverter::Import(aData,aGraphic);
1219 m_aPreview.setGraphic( aGraphic );
1220 m_aPreview.Invalidate();
1222 else
1224 m_aPreview.Hide();
1225 m_aDocumentInfo.Clear();
1226 m_aDocumentInfo.Show();
1227 Reference<document::XDocumentProperties> xProp(
1228 aPreview, UNO_QUERY);
1229 if ( xProp.is() )
1230 m_aDocumentInfo.fill(xProp,String());
1233 else
1235 m_aPreview.Hide();
1236 m_aDocumentInfo.Hide();
1238 // Why the below code? It might have side effects, as the tree view needs to know
1239 // its current selection for other purposes than the preview, too.
1240 // DBTreeListBox* pTreeView = getCurrentView();
1241 // if ( pTreeView )
1242 // pTreeView->clearCurrentSelection();
1245 catch( const Exception& )
1247 DBG_UNHANDLED_EXCEPTION();
1251 // -----------------------------------------------------------------------------
1252 void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName,
1253 const ::rtl::OUString& _sName,
1254 sal_Bool _bTable)
1256 if ( isPreviewEnabled() )
1258 WaitObject aWaitCursor( this );
1259 m_aPreview.Hide();
1260 m_aDocumentInfo.Hide();
1261 m_pTablePreview->Show();
1262 if ( !m_xFrame.is() )
1266 m_xFrame = Reference < XFrame > ( getBorderWin().getView()->getORB()->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Frame")) ), UNO_QUERY );
1267 m_xFrame->initialize( m_xWindow );
1269 // work-around for #150518#: no layout manager (and thus no toolbars) in the preview
1270 // Must be called after initialize ... but before any other call to this frame.
1271 // Otherwhise frame throws "life time exceptions" as e.g. NON_INITIALIZED
1272 Reference< XPropertySet > xFrameProps( m_xFrame, UNO_QUERY_THROW );
1273 xFrameProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ), makeAny(Reference< XLayoutManager >()) );
1275 Reference<XFramesSupplier> xSup(getBorderWin().getView()->getAppController().getXController()->getFrame(),UNO_QUERY);
1276 if ( xSup.is() )
1278 Reference<XFrames> xFrames = xSup->getFrames();
1279 xFrames->append(m_xFrame);
1282 catch(Exception)
1287 Reference< XDatabaseDocumentUI > xApplication( getBorderWin().getView()->getAppController().getXController(), UNO_QUERY );
1288 ::std::auto_ptr< DatabaseObjectView > pDispatcher( new ResultSetBrowser(
1289 getBorderWin().getView()->getORB(), xApplication, NULL, _bTable
1290 ) );
1291 pDispatcher->setTargetFrame( m_xFrame );
1293 Sequence < PropertyValue > aArgs( 4 );
1294 aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Preview"));
1295 aArgs[0].Value <<= sal_True;
1296 aArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
1297 aArgs[1].Value <<= sal_True;
1298 aArgs[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate"));
1299 aArgs[2].Value <<= sal_False;
1300 aArgs[3].Name = PROPERTY_SHOWMENU;
1301 aArgs[3].Value <<= sal_False;
1303 Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY );
1304 sal_Bool bClearPreview = !xPreview.is();
1306 // clear the preview when the query or table could not be loaded
1307 if ( !bClearPreview )
1309 Reference< XTabController > xTabController( xPreview, UNO_QUERY );
1310 bClearPreview = !xTabController.is();
1311 if ( !bClearPreview )
1313 Reference< XLoadable > xLoadable( xTabController->getModel(), UNO_QUERY );
1314 bClearPreview = !( xLoadable.is() && xLoadable->isLoaded() );
1317 if ( bClearPreview )
1318 showPreview(NULL);
1321 // -----------------------------------------------------------------------------
1322 IMPL_LINK(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, /*pToolBox*/)
1324 m_aTBPreview.EndSelection();
1326 // tell the toolbox that the item is pressed down
1327 m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_True );
1329 // simulate a mouse move (so the "down" state is really painted)
1330 Point aPoint = m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ).TopLeft();
1331 MouseEvent aMove( aPoint, 0, MOUSE_SIMPLEMOVE | MOUSE_SYNTHETIC );
1332 m_aTBPreview.MouseMove( aMove );
1334 m_aTBPreview.Update();
1336 // execute the menu
1337 ::std::auto_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
1339 sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
1340 , SID_DB_APP_VIEW_DOC_PREVIEW
1341 , SID_DB_APP_VIEW_DOCINFO_PREVIEW
1344 for(size_t i=0; i < sizeof(pActions)/sizeof(pActions[0]);++i)
1346 aMenu->CheckItem(pActions[i],m_aMenu->IsItemChecked(pActions[i]));
1348 aMenu->EnableItem( SID_DB_APP_VIEW_DOCINFO_PREVIEW, getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) );
1350 // no disabled entries
1351 aMenu->RemoveDisabledEntries();
1353 sal_uInt16 nSelectedAction = aMenu->Execute(&m_aTBPreview, m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ));
1354 // "cleanup" the toolbox state
1355 MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
1356 m_aTBPreview.MouseMove( aLeave );
1357 m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_False);
1358 if ( nSelectedAction )
1360 m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, aMenu->GetItemText(nSelectedAction));
1361 Resize();
1362 getBorderWin().getView()->getAppController().executeChecked(nSelectedAction,Sequence<PropertyValue>());
1364 return 0L;
1367 // -----------------------------------------------------------------------------
1368 void OAppDetailPageHelper::KeyInput( const KeyEvent& rKEvt )
1370 SvTreeListBox* pCurrentView = getCurrentView();
1371 OSL_PRECOND( pCurrentView, "OAppDetailPageHelper::KeyInput: how this?" );
1373 KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); (void)eFunc;
1374 USHORT nCode = rKEvt.GetKeyCode().GetCode();
1376 if ( ( KEY_RETURN == nCode ) && pCurrentView )
1378 getBorderWin().getView()->getAppController().onEntryDoubleClick( *pCurrentView );
1380 else
1381 Window::KeyInput(rKEvt);
1384 // -----------------------------------------------------------------------------
1385 void OAppDetailPageHelper::DataChanged( const DataChangedEvent& rDCEvt )
1387 Window::DataChanged( rDCEvt );
1389 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1390 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1391 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1392 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1393 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1396 ImplInitSettings();
1397 if ( m_pLists[ E_TABLE ] )
1399 OTableTreeListBox* pTableTree = dynamic_cast< OTableTreeListBox* >( m_pLists[ E_TABLE ] );
1400 OSL_ENSURE( pTableTree != NULL, "OAppDetailPageHelper::DataChanged: a tree list for tables which is no TableTreeList?" );
1401 if ( pTableTree )
1402 pTableTree->notifyHiContrastChanged();
1406 // -----------------------------------------------------------------------------
1407 void OAppDetailPageHelper::ImplInitSettings()
1409 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1410 if( true )
1412 Font aFont;
1413 aFont = rStyleSettings.GetFieldFont();
1414 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1415 SetPointFont( aFont );
1416 m_aTBPreview.SetPointFont( aFont );
1419 if( true )
1421 SetTextColor( rStyleSettings.GetFieldTextColor() );
1422 SetTextFillColor();
1423 m_aBorder.SetTextColor( rStyleSettings.GetFieldTextColor() );
1424 m_aBorder.SetTextFillColor();
1425 m_aTBPreview.SetTextColor( rStyleSettings.GetFieldTextColor() );
1426 m_aTBPreview.SetTextFillColor();
1427 } // if( true )
1429 if( true )
1431 SetBackground( rStyleSettings.GetFieldColor() );
1432 m_aBorder.SetBackground( rStyleSettings.GetFieldColor() );
1433 m_aFL.SetBackground( rStyleSettings.GetFieldColor() );
1434 m_aDocumentInfo.SetBackground( rStyleSettings.GetFieldColor() );
1435 m_aTBPreview.SetBackground( rStyleSettings.GetFieldColor() );
1436 m_pTablePreview->SetBackground( rStyleSettings.GetFieldColor() );
1437 } // if( true )
1439 // -----------------------------------------------------------------------------
1440 OPreviewWindow::OPreviewWindow(Window* _pParent)
1441 : Window(_pParent)
1443 ImplInitSettings( sal_True, sal_True, sal_True );
1445 // -----------------------------------------------------------------------------
1446 BOOL OPreviewWindow::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
1448 const Size aWinSize( GetOutputSizePixel() );
1449 Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
1450 BOOL bRet = FALSE;
1452 if( aNewSize.Width() && aNewSize.Height() )
1454 // scale to fit window
1455 const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
1456 const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
1458 if ( fGrfWH < fWinWH )
1460 aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
1461 aNewSize.Height()= aWinSize.Height();
1463 else
1465 aNewSize.Width() = aWinSize.Width();
1466 aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
1469 const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
1470 ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
1472 rResultRect = Rectangle( aNewPos, aNewSize );
1473 bRet = TRUE;
1476 return bRet;
1479 // ------------------------------------------------------------------------
1481 void OPreviewWindow::Paint( const Rectangle& rRect )
1483 Window::Paint( rRect );
1485 if( ImplGetGraphicCenterRect( m_aGraphicObj.GetGraphic(), m_aPreviewRect ) )
1487 const Point aPos( m_aPreviewRect.TopLeft() );
1488 const Size aSize( m_aPreviewRect.GetSize() );
1490 if( m_aGraphicObj.IsAnimated() )
1491 m_aGraphicObj.StartAnimation( this, aPos, aSize );
1492 else
1493 m_aGraphicObj.Draw( this, aPos, aSize );
1496 // -----------------------------------------------------------------------------
1497 void OPreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
1499 Window::DataChanged( rDCEvt );
1501 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1502 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1504 ImplInitSettings( sal_True, sal_True, sal_True );
1505 Invalidate();
1508 // -----------------------------------------------------------------------------
1509 void OPreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
1511 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1512 if( bFont )
1514 Font aFont;
1515 aFont = rStyleSettings.GetFieldFont();
1516 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1517 SetPointFont( aFont );
1520 if( bForeground || bFont )
1522 SetTextColor( rStyleSettings.GetFieldTextColor() );
1523 SetTextFillColor();
1524 } // if( bForeground || bFont )
1526 if( bBackground )
1527 SetBackground( rStyleSettings.GetFieldColor() );
1529 // -----------------------------------------------------------------------------
1530 // -----------------------------------------------------------------------------