1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 #ifndef DBAUI_APPDETAILPAGEHELPER_HXX
31 #include "AppDetailPageHelper.hxx"
32 #endif
33 #ifndef _DBAUI_MODULE_DBU_HXX_
34 #include "moduledbu.hxx"
35 #endif
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
38 #endif
39 #ifndef TOOLS_DIAGNOSE_EX_H
40 #include <tools/diagnose_ex.h>
41 #endif
42 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
43 #include <connectivity/dbtools.hxx>
44 #endif
45 #ifndef _DBAUI_TABLETREE_HXX_
46 #include "tabletree.hxx"
47 #endif
48 #ifndef DBAUI_TOOLS_HXX
49 #include "UITools.hxx"
50 #endif
51 #ifndef DBAUI_DBTREELISTBOX_HXX
52 #include "dbtreelistbox.hxx"
53 #endif
54 #ifndef _COM_SUN_STAR_FRAME_XLAYOUTMANAGER_HPP_
55 #include <com/sun/star/frame/XLayoutManager.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
58 #include <com/sun/star/beans/XPropertySet.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_AWT_XTABCONTROLLER_HPP_
61 #include <com/sun/star/awt/XTabController.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
64 #include <com/sun/star/sdbc/XConnection.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
67 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
70 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
71 #endif
72 #ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
73 #include <com/sun/star/frame/XFrame.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
76 #include <com/sun/star/frame/FrameSearchFlag.hpp>
77 #endif
78 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
79 #include <com/sun/star/frame/XComponentLoader.hpp>
80 #endif
81 #ifndef _COM_SUN_STAR_FRAME_XFRAMES_HPP_
82 #include <com/sun/star/frame/XFrames.hpp>
83 #endif
84 #ifndef _COM_SUN_STAR_FRAME_XFRAMESSUPPLIER_HPP_
85 #include <com/sun/star/frame/XFramesSupplier.hpp>
86 #endif
87 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
88 #include <com/sun/star/awt/XWindow.hpp>
89 #endif
90 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
91 #include <toolkit/helper/vclunohelper.hxx>
92 #endif
93 #ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_
94 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
95 #endif
96 #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
97 #include <com/sun/star/ucb/XCommandProcessor.hpp>
98 #endif
99 #ifndef _COM_SUN_STAR_UCB_COMMAND_HPP_
100 #include <com/sun/star/ucb/Command.hpp>
101 #endif
102 #ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_
103 #include <com/sun/star/form/XLoadable.hpp>
104 #endif
105 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
106 #include <com/sun/star/container/XChild.hpp>
107 #endif
108 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
109 #include <com/sun/star/container/XContainer.hpp>
110 #endif
111 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
112 #include <com/sun/star/sdb/CommandType.hpp>
113 #endif
114 #ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
115 #include <com/sun/star/util/XCloseable.hpp>
116 #endif
117 #ifndef _COM_SUN_STAR_SDB_APPLICATION_XDATABASEDOCUMENTUI_HPP_
118 #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
119 #endif
120 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
121 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
122 #ifndef DBAUI_APPVIEW_HXX
123 #include "AppView.hxx"
124 #endif
125 #ifndef _DBA_DBACCESS_HELPID_HRC_
126 #include "dbaccess_helpid.hrc"
127 #endif
128 #ifndef _DBU_APP_HRC_
129 #include "dbu_app.hrc"
130 #endif
131 #ifndef _DBACCESS_UI_CALLBACKS_HXX_
132 #include "callbacks.hxx"
133 #endif
134 #ifndef DBAUI_ICONTROLLER_HXX
135 #include "IController.hxx"
136 #endif
137 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
138 #include "dbustrings.hrc"
139 #endif
140 #ifndef _DBACCESS_SLOTID_HRC_
141 #include "dbaccess_slotid.hrc"
142 #endif
143 #ifndef DBACCESS_DATABASE_OBJECT_VIEW_HXX
144 #include "databaseobjectview.hxx"
145 #endif
146 #ifndef DBACCESS_IMAGEPROVIDER_HXX
147 #include "imageprovider.hxx"
148 #endif
149 #ifndef _SV_WAITOBJ_HXX
150 #include <vcl/waitobj.hxx>
151 #endif
152 #ifndef _STREAM_HXX
153 #include <tools/stream.hxx>
154 #endif
155 #ifndef _TOOLS_DEBUG_HXX
156 #include <tools/debug.hxx>
157 #endif
158 #ifndef _RTL_USTRBUF_HXX_
159 #include <rtl/ustrbuf.hxx>
160 #endif
161 #include "IApplicationController.hxx"
162 
163 #include <com/sun/star/document/XDocumentProperties.hpp>
164 
165 
166 using namespace ::dbaui;
167 using namespace ::com::sun::star::container;
168 using namespace ::com::sun::star::uno;
169 using namespace ::com::sun::star::ucb;
170 using namespace ::com::sun::star::frame;
171 using namespace ::com::sun::star::form;
172 using namespace ::com::sun::star::sdb;
173 using namespace ::com::sun::star::sdb::application;
174 using namespace ::com::sun::star::sdbc;
175 using namespace ::com::sun::star::sdbcx;
176 using namespace ::com::sun::star::beans;
177 using namespace ::com::sun::star;
178 using ::com::sun::star::awt::XTabController;
179 
180 namespace dbaui
181 {
182     namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
183     namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
184 }
185 
186 namespace
187 {
188     SvLBoxEntry* lcl_findEntry_impl(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvLBoxEntry* _pFirst)
189     {
190         SvLBoxEntry* pReturn = NULL;
191         sal_Int32 nIndex = 0;
192         String sName( _rName.getToken(0,'/',nIndex) );
193 
194         SvLBoxEntry* pEntry = _pFirst;
195         while( pEntry )
196         {
197             if ( rTree.GetEntryText(pEntry) == sName )
198             {
199                 if ( nIndex != -1 )
200                 {
201                     sName = _rName.getToken(0,'/',nIndex);
202                     pEntry = rTree.FirstChild(pEntry);
203                 }
204                 else
205                 {
206                     pReturn = pEntry;
207                     break;
208                 }
209             }
210             else
211                 pEntry = rTree.NextSibling(pEntry);
212         }
213         return pReturn;
214     }
215     SvLBoxEntry* lcl_findEntry(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvLBoxEntry* _pFirst)
216     {
217         sal_Int32 nIndex = 0;
218         ::rtl::OUString sErase = _rName.getToken(0,'/',nIndex); // we don't want to have the "private:forms" part
219         return (nIndex != -1 ? lcl_findEntry_impl(rTree,_rName.copy(sErase.getLength() + 1),_pFirst) : NULL);
220     }
221     //==================================================================
222     // class OPreviewWindow
223     //==================================================================
224     class OTablePreviewWindow : public Window
225     {
226         DECL_LINK(OnDisableInput, void*);
227         void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
228     protected:
229         virtual void DataChanged(const DataChangedEvent& rDCEvt);
230     public:
231         OTablePreviewWindow( Window* pParent, WinBits nStyle = 0 );
232         virtual long Notify( NotifyEvent& rNEvt );
233     };
234     // -----------------------------------------------------------------------------
235     OTablePreviewWindow::OTablePreviewWindow(Window* pParent, WinBits nStyle) : Window( pParent, nStyle)
236     {
237         ImplInitSettings( sal_True, sal_True, sal_True );
238     }
239     // -----------------------------------------------------------------------------
240     long OTablePreviewWindow::Notify( NotifyEvent& rNEvt )
241     {
242         long nRet = Window::Notify( rNEvt );
243         if ( rNEvt.GetType() == EVENT_INPUTENABLE && IsInputEnabled() )
244             PostUserEvent( LINK( this, OTablePreviewWindow, OnDisableInput) );
245         return nRet;
246     }
247     // -----------------------------------------------------------------------------
248     IMPL_LINK(OTablePreviewWindow, OnDisableInput, void*, EMPTYARG)
249     {
250         EnableInput(sal_False);
251         return 0L;
252     }
253     // -----------------------------------------------------------------------------
254     void OTablePreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
255     {
256         Window::DataChanged( rDCEvt );
257 
258         if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
259             (rDCEvt.GetFlags() & SETTINGS_STYLE) )
260         {
261             ImplInitSettings( sal_True, sal_True, sal_True );
262             Invalidate();
263         }
264     }
265     // -----------------------------------------------------------------------------
266     void OTablePreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
267     {
268         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
269         if( bFont )
270         {
271             Font aFont;
272             aFont = rStyleSettings.GetFieldFont();
273             aFont.SetColor( rStyleSettings.GetWindowTextColor() );
274             SetPointFont( aFont );
275         }
276 
277         if( bForeground || bFont )
278         {
279             SetTextColor( rStyleSettings.GetFieldTextColor() );
280             SetTextFillColor();
281         } // if( bForeground || bFont )
282 
283         if( bBackground )
284             SetBackground( rStyleSettings.GetFieldColor() );
285     }
286 
287 }
288 //==================================================================
289 // class OAppDetailPageHelper
290 DBG_NAME(OAppDetailPageHelper)
291 //==================================================================
292 OAppDetailPageHelper::OAppDetailPageHelper(Window* _pParent,OAppBorderWindow& _rBorderWin,PreviewMode _ePreviewMode) : Window(_pParent,WB_DIALOGCONTROL)
293     ,m_rBorderWin(_rBorderWin)
294     ,m_aFL(this,WB_VERT)
295     ,m_aTBPreview(this,WB_TABSTOP )
296     ,m_aBorder(this,WB_BORDER | WB_READONLY)
297     ,m_aPreview(&m_aBorder)
298     ,m_aDocumentInfo(&m_aBorder,WB_LEFT | WB_VSCROLL | WB_READONLY )
299     ,m_pTablePreview(NULL)
300     ,m_ePreviewMode(_ePreviewMode)
301 {
302     DBG_CTOR(OAppDetailPageHelper,NULL);
303 
304     m_aBorder.SetBorderStyle(WINDOW_BORDER_MONO);
305 
306     m_aMenu.reset(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
307 
308     m_aTBPreview.SetOutStyle(TOOLBOX_STYLE_FLAT);
309     m_aTBPreview.InsertItem(SID_DB_APP_DISABLE_PREVIEW,m_aMenu->GetItemText(SID_DB_APP_DISABLE_PREVIEW),TIB_LEFT|TIB_DROPDOWN|TIB_AUTOSIZE|TIB_RADIOCHECK);
310     m_aTBPreview.SetHelpId(HID_APP_VIEW_PREVIEW_CB);
311     m_aTBPreview.SetDropdownClickHdl( LINK( this, OAppDetailPageHelper, OnDropdownClickHdl ) );
312     m_aTBPreview.EnableMenuStrings();
313     m_aTBPreview.Enable(sal_True);
314 
315     m_aBorder.SetUniqueId(UID_APP_VIEW_PREVIEW_1);
316 
317     m_aPreview.SetHelpId(HID_APP_VIEW_PREVIEW_1);
318 
319     m_pTablePreview = new OTablePreviewWindow(&m_aBorder,WB_READONLY | WB_DIALOGCONTROL );
320     m_pTablePreview->SetHelpId(HID_APP_VIEW_PREVIEW_2);
321 
322     m_aDocumentInfo.SetHelpId(HID_APP_VIEW_PREVIEW_3);
323 
324     m_xWindow = VCLUnoHelper::GetInterface( m_pTablePreview );
325 
326     SetUniqueId(UID_APP_DETAILPAGE_HELPER);
327     for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
328         m_pLists[i] = NULL;
329     ImplInitSettings();
330 }
331 // -----------------------------------------------------------------------------
332 OAppDetailPageHelper::~OAppDetailPageHelper()
333 {
334     try
335     {
336         Reference< ::util::XCloseable> xCloseable(m_xFrame,UNO_QUERY);
337         if ( xCloseable.is() )
338             xCloseable->close(sal_True);
339     }
340     catch(Exception)
341     {
342         OSL_ENSURE(0,"Exception thrown while disposing preview frame!");
343     }
344 
345     for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
346     {
347         if ( m_pLists[i] )
348         {
349             m_pLists[i]->clearCurrentSelection();
350             m_pLists[i]->Hide();
351             ::std::auto_ptr<DBTreeListBox> aTemp(m_pLists[i]);
352             m_pLists[i]->clearCurrentSelection();   // why a second time?
353             m_pLists[i] = NULL;
354         }
355 
356     }
357 
358     DBG_DTOR(OAppDetailPageHelper,NULL);
359 }
360 // -----------------------------------------------------------------------------
361 int OAppDetailPageHelper::getVisibleControlIndex() const
362 {
363     int i = 0;
364     for (; i < E_ELEMENT_TYPE_COUNT ; ++i)
365     {
366         if ( m_pLists[i] && m_pLists[i]->IsVisible() )
367             break;
368     }
369     return i;
370 }
371 // -----------------------------------------------------------------------------
372 void OAppDetailPageHelper::selectAll()
373 {
374     int nPos = getVisibleControlIndex();
375     if ( nPos < E_ELEMENT_TYPE_COUNT )
376     {
377         m_pLists[nPos]->SelectAll(sal_True);
378     }
379 }
380 // -----------------------------------------------------------------------------
381 void OAppDetailPageHelper::sort(int _nPos,SvSortMode _eSortMode )
382 {
383     OSL_ENSURE(m_pLists[_nPos],"List can not be NULL! ->GPF");
384     SvLBoxTreeList* pModel = m_pLists[_nPos]->GetModel();
385     SvSortMode eOldSortMode = pModel->GetSortMode();
386     pModel->SetSortMode(_eSortMode);
387     if ( eOldSortMode != _eSortMode )
388         pModel->Resort();
389 }
390 // -----------------------------------------------------------------------------
391 sal_Bool OAppDetailPageHelper::isSortUp() const
392 {
393     SvSortMode eSortMode = SortNone;
394     int nPos = getVisibleControlIndex();
395     if ( nPos < E_ELEMENT_TYPE_COUNT )
396     {
397         SvLBoxTreeList* pModel = m_pLists[nPos]->GetModel();
398         eSortMode = pModel->GetSortMode();
399     }
400     return eSortMode == SortAscending;
401 }
402 // -----------------------------------------------------------------------------
403 void OAppDetailPageHelper::sortDown()
404 {
405     int nPos = getVisibleControlIndex();
406     if ( nPos < E_ELEMENT_TYPE_COUNT )
407         sort(nPos,SortDescending);
408 }
409 // -----------------------------------------------------------------------------
410 void OAppDetailPageHelper::sortUp()
411 {
412     int nPos = getVisibleControlIndex();
413     if ( nPos < E_ELEMENT_TYPE_COUNT )
414         sort(nPos,SortAscending);
415 }
416 // -----------------------------------------------------------------------------
417 void OAppDetailPageHelper::getSelectionElementNames( ::std::vector< ::rtl::OUString>& _rNames ) const
418 {
419     int nPos = getVisibleControlIndex();
420     if ( nPos < E_ELEMENT_TYPE_COUNT )
421     {
422         DBTreeListBox& rTree = *m_pLists[nPos];
423         sal_Int32 nCount = rTree.GetEntryCount();
424         _rNames.reserve(nCount);
425         SvLBoxEntry* pEntry = rTree.FirstSelected();
426         ElementType eType = getElementType();
427         while( pEntry )
428         {
429             if ( eType == E_TABLE )
430             {
431                 if( rTree.GetChildCount(pEntry) == 0 )
432                     _rNames.push_back( getQualifiedName( pEntry ) );
433             }
434             else
435             {
436                 ::rtl::OUString sName = rTree.GetEntryText(pEntry);
437                 SvLBoxEntry* pParent = rTree.GetParent(pEntry);
438                 while(pParent)
439                 {
440                     sName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
441                     pParent = rTree.GetParent(pParent);
442                 }
443                 _rNames.push_back(sName);
444             }
445             pEntry = rTree.NextSelected(pEntry);
446         }
447     }
448 }
449 
450 // -----------------------------------------------------------------------------
451 void OAppDetailPageHelper::describeCurrentSelectionForControl( const Control& _rControl, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
452 {
453     enum ElementType eType = E_TABLE;
454     for ( size_t i=0; i < E_ELEMENT_TYPE_COUNT; eType = static_cast< ElementType >( ++i ) )
455     {
456         if ( m_pLists[eType] == &_rControl )
457         {
458             describeCurrentSelectionForType( eType, _out_rSelectedObjects );
459             return;
460         }
461     }
462     OSL_ENSURE( false, "OAppDetailPageHelper::describeCurrentSelectionForControl: invalid control!" );
463 }
464 
465 // -----------------------------------------------------------------------------
466 void OAppDetailPageHelper::describeCurrentSelectionForType( const ElementType _eType, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
467 {
468     OSL_ENSURE( _eType < E_ELEMENT_TYPE_COUNT, "OAppDetailPageHelper::describeCurrentSelectionForType: invalid type!" );
469     DBTreeListBox* pList = ( _eType < E_ELEMENT_TYPE_COUNT ) ? m_pLists[ _eType ] : NULL;
470     OSL_ENSURE( pList, "OAppDetailPageHelper::describeCurrentSelectionForType: "
471                        "You really should ensure this type has already been viewed before!" );
472     if ( !pList )
473         return;
474 
475     ::std::vector< NamedDatabaseObject > aSelected;
476 
477     SvLBoxEntry* pEntry = pList->FirstSelected();
478     while( pEntry )
479     {
480         NamedDatabaseObject aObject;
481         switch ( _eType )
482         {
483         case E_TABLE:
484         {
485             OTableTreeListBox& rTableTree = dynamic_cast< OTableTreeListBox& >( *pList );
486             aObject = rTableTree.describeObject( pEntry );
487         }
488         break;
489         case E_QUERY:
490             aObject.Type = DatabaseObject::QUERY;
491             aObject.Name = pList->GetEntryText( pEntry );
492             break;
493 
494         case E_FORM:
495         case E_REPORT:
496         {
497             ::rtl::OUString sName = pList->GetEntryText(pEntry);
498             SvLBoxEntry* pParent = pList->GetParent(pEntry);
499             while ( pParent )
500             {
501                 ::rtl::OUStringBuffer buffer;
502                 buffer.append( pList->GetEntryText( pParent ) );
503                 buffer.append( sal_Unicode( '/' ) );
504                 buffer.append( sName );
505                 sName = buffer.makeStringAndClear();
506 
507                 pParent = pList->GetParent( pParent );
508             }
509 
510             if ( isLeaf( pEntry ) )
511                 aObject.Type = ( _eType == E_FORM ) ? DatabaseObject::FORM : DatabaseObject::REPORT;
512             else
513                 aObject.Type = ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER : DatabaseObjectContainer::REPORTS_FOLDER;
514             aObject.Name = sName;
515         }
516         break;
517         default:
518             OSL_ENSURE( false, "OAppDetailPageHelper::describeCurrentSelectionForType: unexpected type!" );
519             break;
520         }
521 
522         if ( aObject.Name.getLength() )
523         {
524             aSelected.push_back( aObject );
525         }
526 
527         pEntry = pList->NextSelected(pEntry);
528     }
529 
530     _out_rSelectedObjects.realloc( aSelected.size() );
531     ::std::copy( aSelected.begin(), aSelected.end(), _out_rSelectedObjects.getArray() );
532 }
533 
534 // -----------------------------------------------------------------------------
535 void OAppDetailPageHelper::selectElements(const Sequence< ::rtl::OUString>& _aNames)
536 {
537     int nPos = getVisibleControlIndex();
538     if ( nPos < E_ELEMENT_TYPE_COUNT )
539     {
540         DBTreeListBox& rTree = *m_pLists[nPos];
541         rTree.SelectAll(sal_False);
542         const ::rtl::OUString* pIter = _aNames.getConstArray();
543         const ::rtl::OUString* pEnd  = pIter + _aNames.getLength();
544         for(;pIter != pEnd;++pIter)
545         {
546             SvLBoxEntry* pEntry = rTree.GetEntryPosByName(*pIter);
547             if ( pEntry )
548                 rTree.Select(pEntry);
549         }
550     }
551 }
552 // -----------------------------------------------------------------------------
553 ::rtl::OUString OAppDetailPageHelper::getQualifiedName( SvLBoxEntry* _pEntry ) const
554 {
555     int nPos = getVisibleControlIndex();
556     ::rtl::OUString sComposedName;
557 
558     if ( nPos >= E_ELEMENT_TYPE_COUNT )
559         return sComposedName;
560 
561     OSL_ENSURE(m_pLists[nPos],"Tables tree view is NULL! -> GPF");
562     DBTreeListBox& rTree = *m_pLists[nPos];
563 
564     SvLBoxEntry* pEntry = _pEntry;
565     if ( !pEntry )
566         pEntry = rTree.FirstSelected();
567 
568     if ( !pEntry )
569         return sComposedName;
570 
571     if ( getElementType() == E_TABLE )
572     {
573         const OTableTreeListBox& rTreeView = dynamic_cast< const OTableTreeListBox& >( *m_pLists[nPos] );
574         sComposedName = rTreeView.getQualifiedTableName( pEntry );
575     }
576     else
577     {
578         sComposedName = rTree.GetEntryText(pEntry);
579         SvLBoxEntry* pParent = rTree.GetParent(pEntry);
580         while(pParent)
581         {
582             sComposedName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sComposedName;
583             pParent = rTree.GetParent(pParent);
584         }
585     }
586 
587     return sComposedName;
588 }
589 // -----------------------------------------------------------------------------
590 ElementType OAppDetailPageHelper::getElementType() const
591 {
592     int nPos = getVisibleControlIndex();
593     return static_cast<ElementType>(nPos);
594 }
595 // -----------------------------------------------------------------------------
596 sal_Int32 OAppDetailPageHelper::getSelectionCount()
597 {
598     sal_Int32 nCount = 0;
599     int nPos = getVisibleControlIndex();
600     if ( nPos < E_ELEMENT_TYPE_COUNT )
601     {
602         DBTreeListBox& rTree = *m_pLists[nPos];
603         SvLBoxEntry* pEntry = rTree.FirstSelected();
604         while( pEntry )
605         {
606             ++nCount;
607             pEntry = rTree.NextSelected(pEntry);
608         }
609     }
610     return nCount;
611 }
612 // -----------------------------------------------------------------------------
613 sal_Int32 OAppDetailPageHelper::getElementCount()
614 {
615     sal_Int32 nCount = 0;
616     int nPos = getVisibleControlIndex();
617     if ( nPos < E_ELEMENT_TYPE_COUNT )
618     {
619         nCount = m_pLists[nPos]->GetEntryCount();
620     }
621     return nCount;
622 }
623 // -----------------------------------------------------------------------------
624 sal_Bool OAppDetailPageHelper::isCutAllowed()
625 {
626     return sal_False;
627 }
628 // -----------------------------------------------------------------------------
629 sal_Bool OAppDetailPageHelper::isCopyAllowed()
630 {
631     //int nPos = getVisibleControlIndex();
632     return sal_True;
633 }
634 // -----------------------------------------------------------------------------
635 sal_Bool OAppDetailPageHelper::isPasteAllowed()
636 {
637     //int nPos = getVisibleControlIndex();
638     return sal_True;
639 }
640 // -----------------------------------------------------------------------------
641 void OAppDetailPageHelper::copy()
642 {
643 }
644 // -----------------------------------------------------------------------------
645 void OAppDetailPageHelper::cut()
646 {
647 }
648 // -----------------------------------------------------------------------------
649 void OAppDetailPageHelper::paste()
650 {
651 }
652 // -----------------------------------------------------------------------------
653 bool OAppDetailPageHelper::isLeaf(SvLBoxEntry* _pEntry) const
654 {
655     if ( !_pEntry )
656         return false;
657     sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() );
658     if  (   ( nEntryType == DatabaseObjectContainer::TABLES )
659         ||  ( nEntryType == DatabaseObjectContainer::CATALOG )
660         ||  ( nEntryType == DatabaseObjectContainer::SCHEMA )
661         ||  ( nEntryType == DatabaseObjectContainer::FORMS_FOLDER )
662         ||  ( nEntryType == DatabaseObjectContainer::REPORTS_FOLDER )
663         )
664         return false;
665 
666     return true;
667 }
668 
669 // -----------------------------------------------------------------------------
670 sal_Bool OAppDetailPageHelper::isALeafSelected() const
671 {
672     int nPos = getVisibleControlIndex();
673     sal_Bool bLeafSelected = sal_False;
674     if ( nPos < E_ELEMENT_TYPE_COUNT )
675     {
676         DBTreeListBox& rTree = *m_pLists[nPos];
677         SvLBoxEntry* pEntry = rTree.FirstSelected( );
678         while( !bLeafSelected && pEntry )
679         {
680             bLeafSelected = isLeaf( pEntry );
681             pEntry = rTree.NextSelected(pEntry);
682         }
683     }
684     return bLeafSelected;
685 }
686 // -----------------------------------------------------------------------------
687 SvLBoxEntry* OAppDetailPageHelper::getEntry( const Point& _aPosPixel) const
688 {
689     SvLBoxEntry* pReturn = NULL;
690     int nPos = getVisibleControlIndex();
691     if ( nPos < E_ELEMENT_TYPE_COUNT )
692         pReturn = m_pLists[nPos]->GetEntry( _aPosPixel,sal_True );
693     return pReturn;
694 }
695 // -----------------------------------------------------------------------------
696 void OAppDetailPageHelper::createTablesPage(const Reference< XConnection>& _xConnection)
697 {
698     OSL_ENSURE(_xConnection.is(),"Connection is NULL! -> GPF");
699 
700     if ( !m_pLists[E_TABLE] )
701     {
702         OTableTreeListBox* pTreeView = new OTableTreeListBox(this
703                                                             ,getBorderWin().getView()->getORB()
704                                                             ,WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP
705                                                             ,sal_False);
706         pTreeView->SetHelpId(HID_APP_TABLE_TREE);
707         m_pLists[E_TABLE] = pTreeView;
708 
709         ImageProvider aImageProvider( _xConnection );
710         createTree( pTreeView,
711             aImageProvider.getDefaultImage( DatabaseObject::TABLE, false ),
712             aImageProvider.getDefaultImage( DatabaseObject::TABLE, true )
713         );
714 
715         pTreeView->notifyHiContrastChanged();
716         m_aBorder.SetZOrder(pTreeView, WINDOW_ZORDER_BEHIND);
717     }
718     if ( !m_pLists[E_TABLE]->GetEntryCount() )
719     {
720         static_cast<OTableTreeListBox*>(m_pLists[E_TABLE])->UpdateTableList(_xConnection);
721 
722         SvLBoxEntry* pEntry = m_pLists[E_TABLE]->First();
723         if ( pEntry )
724             m_pLists[E_TABLE]->Expand(pEntry);
725         m_pLists[E_TABLE]->SelectAll(sal_False);
726     }
727 
728     setDetailPage(m_pLists[E_TABLE]);
729 }
730 
731 // -----------------------------------------------------------------------------
732 void OAppDetailPageHelper::getElementIcons( ElementType _eType, sal_uInt16& _rImageId, sal_uInt16& _rHighContrastImageId )
733 {
734     ImageProvider aImageProvider;
735     _rImageId = _rHighContrastImageId = 0;
736 
737     sal_Int32 nDatabaseObjectType( 0 );
738     switch(_eType )
739     {
740         case E_FORM:    nDatabaseObjectType = DatabaseObject::FORM; break;
741         case E_REPORT:  nDatabaseObjectType = DatabaseObject::REPORT; break;
742         case E_QUERY:   nDatabaseObjectType = DatabaseObject::QUERY; break;
743         default:
744             OSL_ENSURE( sal_False, "OAppDetailPageHelper::GetElementIcons: invalid element type!" );
745             return;
746     }
747     _rImageId = aImageProvider.getDefaultImageResourceID( nDatabaseObjectType, false );
748     _rHighContrastImageId = aImageProvider.getDefaultImageResourceID( nDatabaseObjectType, true );
749 }
750 
751 // -----------------------------------------------------------------------------
752 void OAppDetailPageHelper::createPage(ElementType _eType,const Reference< XNameAccess >& _xContainer)
753 {
754     OSL_ENSURE(E_TABLE != _eType,"E_TABLE isn't allowed.");
755 
756     sal_uInt16 nImageId = 0, nImageIdH = 0;
757     rtl::OString sHelpId;
758     ImageProvider aImageProvider;
759     Image aFolderImage, aFolderImageHC;
760     switch( _eType )
761     {
762         case E_FORM:
763             sHelpId = HID_APP_FORM_TREE;
764             aFolderImage = aImageProvider.getFolderImage( DatabaseObject::FORM, false );
765             aFolderImageHC = aImageProvider.getFolderImage( DatabaseObject::FORM, true );
766             break;
767         case E_REPORT:
768             sHelpId = HID_APP_REPORT_TREE;
769             aFolderImage = aImageProvider.getFolderImage( DatabaseObject::REPORT, false );
770             aFolderImageHC = aImageProvider.getFolderImage( DatabaseObject::REPORT, true );
771             break;
772         case E_QUERY:
773             sHelpId = HID_APP_QUERY_TREE;
774             aFolderImage = aImageProvider.getFolderImage( DatabaseObject::QUERY, false );
775             aFolderImageHC = aImageProvider.getFolderImage( DatabaseObject::QUERY, true );
776             break;
777         default:
778             OSL_ENSURE(0,"Illegal call!");
779     }
780     getElementIcons( _eType, nImageId, nImageIdH );
781 
782     if ( !m_pLists[_eType] )
783     {
784         m_pLists[_eType] = createSimpleTree( sHelpId, aFolderImage, aFolderImageHC );
785     }
786 
787     if ( m_pLists[_eType] )
788     {
789         if ( !m_pLists[_eType]->GetEntryCount() && _xContainer.is() )
790         {
791             fillNames( _xContainer, _eType, nImageId, nImageIdH, NULL );
792 
793             m_pLists[_eType]->SelectAll(sal_False);
794         }
795         setDetailPage(m_pLists[_eType]);
796     }
797 }
798 // -----------------------------------------------------------------------------
799 void OAppDetailPageHelper::setDetailPage(Window* _pWindow)
800 {
801     OSL_ENSURE(_pWindow,"OAppDetailPageHelper::setDetailPage: Window is NULL!");
802     Window* pCurrent = getCurrentView();
803     if ( pCurrent )
804         pCurrent->Hide();
805 
806     showPreview(NULL);
807     sal_Bool bHasFocus = sal_False;
808     m_aFL.Show();
809     {
810         bHasFocus = pCurrent->HasChildPathFocus();
811     _pWindow->Show();
812     }
813     m_aTBPreview.Show();
814     m_aBorder.Show();
815     switchPreview(m_ePreviewMode,sal_True);
816 
817     if ( bHasFocus )
818         _pWindow->GrabFocus();
819     Resize();
820 }
821 
822 // -----------------------------------------------------------------------------
823 namespace
824 {
825     namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
826     namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
827 
828     static sal_Int32 lcl_getFolderIndicatorForType( const ElementType _eType )
829     {
830         const sal_Int32 nFolderIndicator =
831                 ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER
832             :   ( _eType == E_REPORT ) ? DatabaseObjectContainer::REPORTS_FOLDER : -1;
833         return nFolderIndicator;
834     }
835 }
836 
837 // -----------------------------------------------------------------------------
838 void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, const ElementType _eType,
839                                       const sal_uInt16 _nImageId, const sal_uInt16 _nHighContrastImageId, SvLBoxEntry* _pParent )
840 {
841     OSL_ENSURE(_xContainer.is(),"Data source is NULL! -> GPF");
842     OSL_ENSURE( ( _eType >= E_TABLE ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OAppDetailPageHelper::fillNames: invalid type!" );
843 
844     DBTreeListBox* pList = m_pLists[ _eType ];
845     OSL_ENSURE( pList, "OAppDetailPageHelper::fillNames: you really should create the list before calling this!" );
846     if ( !pList )
847         return;
848 
849     if ( _xContainer.is() && _xContainer->hasElements() )
850     {
851         const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
852 
853         Sequence< ::rtl::OUString> aSeq = _xContainer->getElementNames();
854         const ::rtl::OUString* pIter = aSeq.getConstArray();
855         const ::rtl::OUString* pEnd  = pIter + aSeq.getLength();
856         for(;pIter != pEnd;++pIter)
857         {
858             SvLBoxEntry* pEntry = NULL;
859             Reference<XNameAccess> xSubElements(_xContainer->getByName(*pIter),UNO_QUERY);
860             if ( xSubElements.is() )
861             {
862                 pEntry = pList->InsertEntry( *pIter, _pParent, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
863                 getBorderWin().getView()->getAppController().containerFound( Reference< XContainer >( xSubElements, UNO_QUERY ) );
864                 fillNames( xSubElements, _eType, _nImageId, _nHighContrastImageId, pEntry );
865             }
866             else
867             {
868                 pEntry = pList->InsertEntry( *pIter, _pParent );
869 
870                 Image aImage = Image( ModuleRes( _nImageId ) );
871                 pList->SetExpandedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL );
872                 pList->SetCollapsedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL );
873 
874                 Image aHCImage = Image( ModuleRes( _nHighContrastImageId ) );
875                 pList->SetExpandedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST );
876                 pList->SetCollapsedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST );
877             }
878         }
879     }
880 }
881 // -----------------------------------------------------------------------------
882 DBTreeListBox* OAppDetailPageHelper::createSimpleTree( const rtl::OString& _sHelpId, const Image& _rImage, const Image& _rImageHC )
883 {
884     DBTreeListBox* pTreeView = new DBTreeListBox(this,getBorderWin().getView()->getORB(),WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
885     pTreeView->SetHelpId( _sHelpId );
886     return createTree( pTreeView, _rImage, _rImageHC );
887 }
888 
889 // -----------------------------------------------------------------------------
890 DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, const Image& _rImage, const Image& _rImageHC )
891 {
892     WaitObject aWaitCursor(this);
893 
894     _pTreeView->SetStyle(_pTreeView->GetStyle() | WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
895     _pTreeView->GetModel()->SetSortMode(SortAscending);
896     _pTreeView->EnableCheckButton( NULL ); // do not show any buttons
897     _pTreeView->SetSelectionMode(MULTIPLE_SELECTION);
898 
899     _pTreeView->SetDefaultCollapsedEntryBmp( _rImage );
900     _pTreeView->SetDefaultCollapsedEntryBmp( _rImageHC, BMP_COLOR_HIGHCONTRAST );
901     _pTreeView->SetDefaultExpandedEntryBmp( _rImage );
902     _pTreeView->SetDefaultExpandedEntryBmp( _rImageHC, BMP_COLOR_HIGHCONTRAST );
903 
904     _pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
905     _pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
906     _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
907 
908     _pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
909     _pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
910     _pTreeView->setPasteHandler(LINK(this, OAppDetailPageHelper, OnPasteEntry));
911     _pTreeView->setDeleteHandler(LINK(this, OAppDetailPageHelper, OnDeleteEntry));
912 
913     _pTreeView->setControlActionListener( &getBorderWin().getView()->getAppController() );
914     _pTreeView->setContextMenuProvider( &getBorderWin().getView()->getAppController() );
915 
916     return _pTreeView;
917 }
918 // -----------------------------------------------------------------------------
919 void OAppDetailPageHelper::clearPages()
920 {
921     showPreview(NULL);
922     for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
923     {
924         if ( m_pLists[i] )
925             m_pLists[i]->Clear();
926     }
927 }
928 // -----------------------------------------------------------------------------
929 sal_Bool OAppDetailPageHelper::isFilled() const
930 {
931     size_t i = 0;
932     for (; i < E_ELEMENT_TYPE_COUNT && !m_pLists[i]; ++i)
933         ;
934     return i != E_ELEMENT_TYPE_COUNT;
935 }
936 // -----------------------------------------------------------------------------
937 void OAppDetailPageHelper::elementReplaced(ElementType _eType
938                                                     ,const ::rtl::OUString& _rOldName
939                                                     ,const ::rtl::OUString& _rNewName )
940 {
941     DBTreeListBox* pTreeView = getCurrentView();
942     if ( pTreeView )
943     {
944         ::rtl::OUString sNewName = _rNewName;
945         SvLBoxEntry* pEntry = NULL;
946         switch( _eType )
947         {
948             case E_TABLE:
949                 static_cast<OTableTreeListBox*>(pTreeView)->removedTable( _rOldName );
950                 static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rNewName );
951                 return;
952 
953             case E_QUERY:
954                 pEntry = lcl_findEntry_impl(*pTreeView,_rOldName,pTreeView->First());
955                 break;
956             case E_FORM:
957             case E_REPORT:
958                 pEntry = lcl_findEntry(*pTreeView,_rOldName,pTreeView->First());
959                 break;
960             default:
961                 OSL_ENSURE(0,"Invalid element type");
962         }
963         OSL_ENSURE(pEntry,"Do you know that the name isn't existence!");
964         if ( pEntry )
965         {
966             pTreeView->SetEntryText(pEntry,sNewName);
967         }
968     }
969 }
970 // -----------------------------------------------------------------------------
971 SvLBoxEntry* OAppDetailPageHelper::elementAdded(ElementType _eType,const ::rtl::OUString& _rName, const Any& _rObject )
972 {
973     SvLBoxEntry* pRet = NULL;
974     DBTreeListBox* pTreeView = m_pLists[_eType];
975     if( _eType == E_TABLE && pTreeView )
976     {
977         pRet = static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rName );
978     }
979     else if ( pTreeView )
980     {
981 
982         SvLBoxEntry* pEntry = NULL;
983         Reference<XChild> xChild(_rObject,UNO_QUERY);
984         if ( xChild.is() && E_QUERY != _eType )
985         {
986             Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
987             if ( xContent.is() )
988             {
989                 ::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
990                 pEntry = lcl_findEntry(*pTreeView,sName,pTreeView->First());
991             }
992         }
993 
994         sal_uInt16 nImageId = 0, nImageIdH = 0;
995         getElementIcons( _eType, nImageId, nImageIdH );
996         Reference<XNameAccess> xContainer(_rObject,UNO_QUERY);
997         if ( xContainer.is() )
998         {
999             const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
1000             pRet = pTreeView->InsertEntry( _rName, pEntry, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
1001             fillNames( xContainer, _eType, nImageId, nImageIdH, pRet );
1002         }
1003         else
1004         {
1005             pRet = pTreeView->InsertEntry( _rName, pEntry );
1006 
1007             Image aImage = Image( ModuleRes( nImageId ) );
1008             pTreeView->SetExpandedEntryBmp( pRet, aImage, BMP_COLOR_NORMAL );
1009             pTreeView->SetCollapsedEntryBmp( pRet, aImage, BMP_COLOR_NORMAL );
1010 
1011             Image aHCImage = Image( ModuleRes( nImageIdH ) );
1012             pTreeView->SetExpandedEntryBmp( pRet, aHCImage, BMP_COLOR_HIGHCONTRAST );
1013             pTreeView->SetCollapsedEntryBmp( pRet, aHCImage, BMP_COLOR_HIGHCONTRAST );
1014         }
1015     }
1016     return pRet;
1017 }
1018 // -----------------------------------------------------------------------------
1019 void OAppDetailPageHelper::elementRemoved( ElementType _eType,const ::rtl::OUString& _rName )
1020 {
1021     DBTreeListBox* pTreeView = getCurrentView();
1022     if ( pTreeView )
1023     {
1024         switch( _eType )
1025         {
1026             case E_TABLE:
1027                 // we don't need to clear the table here, it is already done by the dispose listener
1028                 static_cast< OTableTreeListBox* >( pTreeView )->removedTable( _rName );
1029                 break;
1030             case E_QUERY:
1031                 if ( pTreeView )
1032                 {
1033                     SvLBoxEntry* pEntry = lcl_findEntry_impl(*pTreeView,_rName,pTreeView->First());
1034                     if ( pEntry )
1035                         pTreeView->GetModel()->Remove(pEntry);
1036                 }
1037                 break;
1038             case E_FORM:
1039             case E_REPORT:
1040                 {
1041                     if ( pTreeView )
1042                     {
1043                         SvLBoxEntry* pEntry = lcl_findEntry(*pTreeView,_rName,pTreeView->First());
1044                         if ( pEntry )
1045                             pTreeView->GetModel()->Remove(pEntry);
1046                     }
1047                 }
1048                 break;
1049             default:
1050                 OSL_ENSURE(0,"Invalid element type");
1051         }
1052         if ( !pTreeView->GetEntryCount() )
1053             showPreview(NULL);
1054     }
1055 }
1056 // -----------------------------------------------------------------------------
1057 IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
1058 {
1059     OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnEntryDoubleClick: invalid callback!" );
1060     bool bHandled = ( _pTree != NULL ) && getBorderWin().getView()->getAppController().onEntryDoubleClick( *_pTree );
1061     return bHandled ? 1L : 0L;
1062 }
1063 // -----------------------------------------------------------------------------
1064 IMPL_LINK(OAppDetailPageHelper, OnEntrySelChange, void*, /*NOINTERESTEDIN*/)
1065 {
1066     getBorderWin().getView()->getAppController().onSelectionChanged();
1067     return 1L;
1068 }
1069 // -----------------------------------------------------------------------------
1070 IMPL_LINK( OAppDetailPageHelper, OnCutEntry, void*, /*NOINTERESTEDIN*/ )
1071 {
1072     getBorderWin().getView()->getAppController().onCutEntry();
1073     return 1L;
1074 }
1075 // -----------------------------------------------------------------------------
1076 IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, void*, /*NOINTERESTEDIN*/ )
1077 {
1078     getBorderWin().getView()->getAppController().onCopyEntry();
1079     return 1L;
1080 }
1081 // -----------------------------------------------------------------------------
1082 IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, void*, /*NOINTERESTEDIN*/ )
1083 {
1084     getBorderWin().getView()->getAppController().onPasteEntry();
1085     return 1L;
1086 }
1087 // -----------------------------------------------------------------------------
1088 IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, void*, /*NOINTERESTEDIN*/ )
1089 {
1090     getBorderWin().getView()->getAppController().onDeleteEntry();
1091     return 1L;
1092 }
1093 // -----------------------------------------------------------------------------
1094 void OAppDetailPageHelper::Resize()
1095 {
1096     //////////////////////////////////////////////////////////////////////
1097     // Abmessungen parent window
1098     Size aOutputSize( GetOutputSize() );
1099     long nOutputWidth  = aOutputSize.Width();
1100     long nOutputHeight = aOutputSize.Height();
1101 
1102     Window* pWindow = getCurrentView();
1103     if ( pWindow )
1104     {
1105         Size aFLSize = LogicToPixel( Size( 2, 6 ), MAP_APPFONT );
1106         sal_Int32 n6PPT = aFLSize.Height();
1107         long nHalfOutputWidth = static_cast<long>(nOutputWidth * 0.5);
1108 
1109         pWindow->SetPosSizePixel( Point(0, 0), Size(nHalfOutputWidth - n6PPT, nOutputHeight) );
1110 
1111         m_aFL.SetPosSizePixel( Point(nHalfOutputWidth , 0 ), Size(aFLSize.Width(), nOutputHeight ) );
1112 
1113         String sText = m_aTBPreview.GetItemText(SID_DB_APP_DISABLE_PREVIEW);
1114         Size aTBSize = m_aTBPreview.CalcWindowSizePixel();
1115         m_aTBPreview.SetPosSizePixel(Point(nOutputWidth - aTBSize.getWidth(), 0 ),
1116                                      aTBSize );
1117 
1118         m_aBorder.SetPosSizePixel(Point(nHalfOutputWidth + aFLSize.Width() + n6PPT, aTBSize.getHeight() + n6PPT ),
1119                                   Size(nHalfOutputWidth - aFLSize.Width() - n6PPT, nOutputHeight - 2*n6PPT - aTBSize.getHeight()) );
1120         m_aPreview.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1121         m_aDocumentInfo.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1122         m_pTablePreview->SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1123     }
1124 }
1125 // -----------------------------------------------------------------------------
1126 PreviewMode OAppDetailPageHelper::getPreviewMode()
1127 {
1128     return m_ePreviewMode;
1129 }
1130 // -----------------------------------------------------------------------------
1131 sal_Bool OAppDetailPageHelper::isPreviewEnabled()
1132 {
1133     return m_ePreviewMode != E_PREVIEWNONE;
1134 }
1135 // -----------------------------------------------------------------------------
1136 void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,sal_Bool _bForce)
1137 {
1138     if ( m_ePreviewMode != _eMode || _bForce )
1139     {
1140         m_ePreviewMode = _eMode;
1141 
1142         getBorderWin().getView()->getAppController().previewChanged(static_cast<sal_Int32>(m_ePreviewMode));
1143 
1144         sal_uInt16 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1145         switch ( m_ePreviewMode )
1146         {
1147             case E_PREVIEWNONE:
1148                 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1149                 break;
1150             case E_DOCUMENT:
1151                 nSelectedAction = SID_DB_APP_VIEW_DOC_PREVIEW;
1152                 break;
1153             case E_DOCUMENTINFO:
1154                 if ( getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) )
1155                     nSelectedAction = SID_DB_APP_VIEW_DOCINFO_PREVIEW;
1156                 else
1157                     m_ePreviewMode = E_PREVIEWNONE;
1158                 break;
1159         }
1160 
1161         m_aMenu->CheckItem(nSelectedAction);
1162         m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
1163         Resize();
1164 
1165         // simulate a selectionChanged event at the controller, to force the preview to be updated
1166         if ( isPreviewEnabled() )
1167         {
1168             if ( getCurrentView() && getCurrentView()->FirstSelected() )
1169             {
1170                 getBorderWin().getView()->getAppController().onSelectionChanged();
1171             }
1172         }
1173         else
1174         {
1175             m_pTablePreview->Hide();
1176             m_aPreview.Hide();
1177             m_aDocumentInfo.Hide();
1178         }
1179     }
1180 }
1181 // -----------------------------------------------------------------------------
1182 void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
1183 {
1184     if ( isPreviewEnabled() )
1185     {
1186         m_pTablePreview->Hide();
1187 
1188         WaitObject aWaitCursor( this );
1189         try
1190         {
1191             Reference<XCommandProcessor> xContent(_xContent,UNO_QUERY);
1192             if ( xContent.is() )
1193             {
1194                 com::sun::star::ucb::Command aCommand;
1195                 if ( m_ePreviewMode == E_DOCUMENT )
1196                     aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("preview"));
1197                 else
1198                     aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getDocumentInfo"));
1199 
1200                 Any aPreview = xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
1201                 if ( m_ePreviewMode == E_DOCUMENT )
1202                 {
1203                     m_aDocumentInfo.Hide();
1204                     m_aPreview.Show();
1205 
1206                     Graphic aGraphic;
1207                     Sequence < sal_Int8 > aBmpSequence;
1208                     if ( aPreview >>= aBmpSequence )
1209                     {
1210                         SvMemoryStream  aData( aBmpSequence.getArray(),
1211                                             aBmpSequence.getLength(),
1212                                             STREAM_READ );
1213 
1214                         GraphicConverter::Import(aData,aGraphic);
1215                     }
1216                     m_aPreview.setGraphic( aGraphic );
1217                     m_aPreview.Invalidate();
1218                 }
1219                 else
1220                 {
1221                     m_aPreview.Hide();
1222                     m_aDocumentInfo.Clear();
1223                     m_aDocumentInfo.Show();
1224                     Reference<document::XDocumentProperties> xProp(
1225                         aPreview, UNO_QUERY);
1226                     if ( xProp.is() )
1227                         m_aDocumentInfo.fill(xProp,String());
1228                 }
1229             }
1230             else
1231             {
1232                 m_aPreview.Hide();
1233                 m_aDocumentInfo.Hide();
1234 
1235                 // Why the below code? It might have side effects, as the tree view needs to know
1236                 // its current selection for other purposes than the preview, too.
1237 //                DBTreeListBox* pTreeView = getCurrentView();
1238 //                if ( pTreeView )
1239 //                    pTreeView->clearCurrentSelection();
1240             }
1241         }
1242         catch( const Exception& )
1243         {
1244             DBG_UNHANDLED_EXCEPTION();
1245         }
1246     }
1247 }
1248 // -----------------------------------------------------------------------------
1249 void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName,
1250                                         const ::rtl::OUString& _sName,
1251                                         sal_Bool _bTable)
1252 {
1253     if ( isPreviewEnabled() )
1254     {
1255         WaitObject aWaitCursor( this );
1256         m_aPreview.Hide();
1257         m_aDocumentInfo.Hide();
1258         m_pTablePreview->Show();
1259         if ( !m_xFrame.is() )
1260         {
1261             try
1262             {
1263                 m_xFrame = Reference < XFrame > ( getBorderWin().getView()->getORB()->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Frame")) ), UNO_QUERY );
1264                 m_xFrame->initialize( m_xWindow );
1265 
1266                 // work-around for #150518#: no layout manager (and thus no toolbars) in the preview
1267                 // Must be called after initialize ... but before any other call to this frame.
1268                 // Otherwhise frame throws "life time exceptions" as e.g. NON_INITIALIZED
1269                 Reference< XPropertySet > xFrameProps( m_xFrame, UNO_QUERY_THROW );
1270                 xFrameProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ), makeAny(Reference< XLayoutManager >()) );
1271 
1272                 Reference<XFramesSupplier> xSup(getBorderWin().getView()->getAppController().getXController()->getFrame(),UNO_QUERY);
1273                 if ( xSup.is() )
1274                 {
1275                     Reference<XFrames> xFrames = xSup->getFrames();
1276                     xFrames->append(m_xFrame);
1277                 }
1278             }
1279             catch(Exception)
1280             {
1281             }
1282         }
1283 
1284         Reference< XDatabaseDocumentUI > xApplication( getBorderWin().getView()->getAppController().getXController(), UNO_QUERY );
1285         ::std::auto_ptr< DatabaseObjectView > pDispatcher( new ResultSetBrowser(
1286             getBorderWin().getView()->getORB(), xApplication, NULL, _bTable
1287         ) );
1288         pDispatcher->setTargetFrame( m_xFrame );
1289 
1290         ::comphelper::NamedValueCollection aArgs;
1291         aArgs.put( "Preview", sal_True );
1292         aArgs.put( "ReadOnly", sal_True );
1293         aArgs.put( "AsTemplate", sal_False );
1294         aArgs.put( (::rtl::OUString)PROPERTY_SHOWMENU, sal_False );
1295 
1296         Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY );
1297         sal_Bool bClearPreview = !xPreview.is();
1298 
1299         // clear the preview when the query or table could not be loaded
1300         if ( !bClearPreview )
1301         {
1302             Reference< XTabController > xTabController( xPreview, UNO_QUERY );
1303             bClearPreview = !xTabController.is();
1304             if ( !bClearPreview )
1305             {
1306                 Reference< XLoadable > xLoadable( xTabController->getModel(), UNO_QUERY );
1307                 bClearPreview = !( xLoadable.is() && xLoadable->isLoaded() );
1308             }
1309         }
1310         if ( bClearPreview )
1311             showPreview(NULL);
1312     }
1313 }
1314 // -----------------------------------------------------------------------------
1315 IMPL_LINK(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, /*pToolBox*/)
1316 {
1317     m_aTBPreview.EndSelection();
1318 
1319     // tell the toolbox that the item is pressed down
1320     m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_True );
1321 
1322     // simulate a mouse move (so the "down" state is really painted)
1323     Point aPoint = m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ).TopLeft();
1324     MouseEvent aMove( aPoint, 0, MOUSE_SIMPLEMOVE | MOUSE_SYNTHETIC );
1325     m_aTBPreview.MouseMove( aMove );
1326 
1327     m_aTBPreview.Update();
1328 
1329     // execute the menu
1330     ::std::auto_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
1331 
1332     sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
1333                             , SID_DB_APP_VIEW_DOC_PREVIEW
1334                             , SID_DB_APP_VIEW_DOCINFO_PREVIEW
1335     };
1336 
1337     for(size_t i=0; i < sizeof(pActions)/sizeof(pActions[0]);++i)
1338     {
1339         aMenu->CheckItem(pActions[i],m_aMenu->IsItemChecked(pActions[i]));
1340     }
1341     aMenu->EnableItem( SID_DB_APP_VIEW_DOCINFO_PREVIEW, getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) );
1342 
1343     // no disabled entries
1344     aMenu->RemoveDisabledEntries();
1345 
1346     sal_uInt16 nSelectedAction = aMenu->Execute(&m_aTBPreview, m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ));
1347     // "cleanup" the toolbox state
1348     MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
1349     m_aTBPreview.MouseMove( aLeave );
1350     m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_False);
1351     if ( nSelectedAction )
1352     {
1353         m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, aMenu->GetItemText(nSelectedAction));
1354         Resize();
1355         getBorderWin().getView()->getAppController().executeChecked(nSelectedAction,Sequence<PropertyValue>());
1356     }
1357     return 0L;
1358 }
1359 
1360 // -----------------------------------------------------------------------------
1361 void OAppDetailPageHelper::KeyInput( const KeyEvent& rKEvt )
1362 {
1363     SvTreeListBox* pCurrentView = getCurrentView();
1364     OSL_PRECOND( pCurrentView, "OAppDetailPageHelper::KeyInput: how this?" );
1365 
1366     KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); (void)eFunc;
1367     sal_uInt16      nCode = rKEvt.GetKeyCode().GetCode();
1368 
1369     if ( ( KEY_RETURN == nCode ) && pCurrentView )
1370     {
1371         getBorderWin().getView()->getAppController().onEntryDoubleClick( *pCurrentView );
1372     }
1373     else
1374         Window::KeyInput(rKEvt);
1375 }
1376 
1377 // -----------------------------------------------------------------------------
1378 void OAppDetailPageHelper::DataChanged( const DataChangedEvent& rDCEvt )
1379 {
1380     Window::DataChanged( rDCEvt );
1381 
1382         if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1383         (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1384         (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1385         ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1386         (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1387 
1388     {
1389         ImplInitSettings();
1390         if ( m_pLists[ E_TABLE ] )
1391         {
1392             OTableTreeListBox* pTableTree = dynamic_cast< OTableTreeListBox* >( m_pLists[ E_TABLE ] );
1393             OSL_ENSURE( pTableTree != NULL, "OAppDetailPageHelper::DataChanged: a tree list for tables which is no TableTreeList?" );
1394             if ( pTableTree )
1395                 pTableTree->notifyHiContrastChanged();
1396         }
1397     }
1398 }
1399 // -----------------------------------------------------------------------------
1400 void OAppDetailPageHelper::ImplInitSettings()
1401 {
1402     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1403     if( true )
1404     {
1405         Font aFont;
1406         aFont = rStyleSettings.GetFieldFont();
1407         aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1408         SetPointFont( aFont );
1409         m_aTBPreview.SetPointFont( aFont );
1410     }
1411 
1412     if( true )
1413     {
1414         SetTextColor( rStyleSettings.GetFieldTextColor() );
1415         SetTextFillColor();
1416         m_aBorder.SetTextColor( rStyleSettings.GetFieldTextColor() );
1417         m_aBorder.SetTextFillColor();
1418         m_aTBPreview.SetTextColor( rStyleSettings.GetFieldTextColor() );
1419         m_aTBPreview.SetTextFillColor();
1420     } // if( true )
1421 
1422     if( true )
1423     {
1424         SetBackground( rStyleSettings.GetFieldColor() );
1425         m_aBorder.SetBackground( rStyleSettings.GetFieldColor() );
1426         m_aFL.SetBackground( rStyleSettings.GetFieldColor() );
1427         m_aDocumentInfo.SetBackground( rStyleSettings.GetFieldColor() );
1428         m_aTBPreview.SetBackground( rStyleSettings.GetFieldColor() );
1429         m_pTablePreview->SetBackground( rStyleSettings.GetFieldColor() );
1430     } // if( true )
1431 }
1432 // -----------------------------------------------------------------------------
1433 OPreviewWindow::OPreviewWindow(Window* _pParent)
1434 : Window(_pParent)
1435 {
1436     ImplInitSettings( sal_True, sal_True, sal_True );
1437 }
1438 // -----------------------------------------------------------------------------
1439 sal_Bool OPreviewWindow::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
1440 {
1441     const Size aWinSize( GetOutputSizePixel() );
1442     Size       aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
1443     sal_Bool       bRet = sal_False;
1444 
1445     if( aNewSize.Width() && aNewSize.Height() )
1446     {
1447         // scale to fit window
1448         const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
1449         const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
1450 
1451         if ( fGrfWH < fWinWH )
1452         {
1453             aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
1454             aNewSize.Height()= aWinSize.Height();
1455         }
1456         else
1457         {
1458             aNewSize.Width() = aWinSize.Width();
1459             aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
1460         }
1461 
1462         const Point aNewPos( ( aWinSize.Width()  - aNewSize.Width() ) >> 1,
1463                              ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
1464 
1465         rResultRect = Rectangle( aNewPos, aNewSize );
1466         bRet = sal_True;
1467     }
1468 
1469     return bRet;
1470 }
1471 
1472 // ------------------------------------------------------------------------
1473 
1474 void OPreviewWindow::Paint( const Rectangle& rRect )
1475 {
1476     Window::Paint( rRect );
1477 
1478     if( ImplGetGraphicCenterRect( m_aGraphicObj.GetGraphic(), m_aPreviewRect ) )
1479     {
1480         const Point aPos( m_aPreviewRect.TopLeft() );
1481         const Size  aSize( m_aPreviewRect.GetSize() );
1482 
1483         if( m_aGraphicObj.IsAnimated() )
1484             m_aGraphicObj.StartAnimation( this, aPos, aSize );
1485         else
1486             m_aGraphicObj.Draw( this, aPos, aSize );
1487     }
1488 }
1489 // -----------------------------------------------------------------------------
1490 void OPreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
1491 {
1492     Window::DataChanged( rDCEvt );
1493 
1494     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1495          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1496     {
1497         ImplInitSettings( sal_True, sal_True, sal_True );
1498         Invalidate();
1499     }
1500 }
1501 // -----------------------------------------------------------------------------
1502 void OPreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
1503 {
1504     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1505     if( bFont )
1506     {
1507         Font aFont;
1508         aFont = rStyleSettings.GetFieldFont();
1509         aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1510         SetPointFont( aFont );
1511     }
1512 
1513     if( bForeground || bFont )
1514     {
1515         SetTextColor( rStyleSettings.GetFieldTextColor() );
1516         SetTextFillColor();
1517     } // if( bForeground || bFont )
1518 
1519     if( bBackground )
1520         SetBackground( rStyleSettings.GetFieldColor() );
1521 }
1522 // -----------------------------------------------------------------------------
1523 // -----------------------------------------------------------------------------
1524 
1525