LCOV - code coverage report
Current view: top level - dbaccess/source/ui/app - AppDetailPageHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 242 708 34.2 %
Date: 2015-06-13 12:38:46 Functions: 29 73 39.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11