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

Generated by: LCOV version 1.10