LCOV - code coverage report
Current view: top level - sfx2/source/dialog - versdlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 338 0.3 %
Date: 2014-11-03 Functions: 2 32 6.2 %
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 <sal/config.h>
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include <boost/scoped_ptr.hpp>
      24             : #include <unotools/localedatawrapper.hxx>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <svl/eitem.hxx>
      27             : #include <svl/intitem.hxx>
      28             : #include <svl/stritem.hxx>
      29             : #include <svl/itemset.hxx>
      30             : #include <unotools/useroptions.hxx>
      31             : #include <vcl/layout.hxx>
      32             : #include <vcl/msgbox.hxx>
      33             : #include <vcl/svapp.hxx>
      34             : #include <vcl/settings.hxx>
      35             : #include <tools/datetime.hxx>
      36             : #include <svtools/treelistentry.hxx>
      37             : #include <svtools/miscopt.hxx>
      38             : 
      39             : #include "versdlg.hxx"
      40             : #include "dialog.hrc"
      41             : #include <sfx2/dialoghelper.hxx>
      42             : #include <sfx2/viewfrm.hxx>
      43             : #include <sfx2/sfxresid.hxx>
      44             : #include <sfx2/docfile.hxx>
      45             : #include <sfx2/objsh.hxx>
      46             : #include <sfx2/sfxsids.hrc>
      47             : #include <sfx2/dispatch.hxx>
      48             : #include <sfx2/request.hxx>
      49             : 
      50             : #include <sfx2/sfxuno.hxx>
      51             : #include <vector>
      52             : 
      53             : using namespace com::sun::star;
      54             : using ::std::vector;
      55             : 
      56             : // **************************************************************************
      57           0 : struct SfxVersionInfo
      58             : {
      59             :     OUString                aName;
      60             :     OUString                aComment;
      61             :     OUString                aAuthor;
      62             :     DateTime                aCreationDate;
      63             : 
      64             :                             SfxVersionInfo();
      65             : };
      66             : 
      67             : typedef vector< SfxVersionInfo* > _SfxVersionTable;
      68             : 
      69             : class SfxVersionTableDtor: private boost::noncopyable
      70             : {
      71             : private:
      72             :     _SfxVersionTable        aTableList;
      73             : public:
      74             :                             SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo );
      75             :                             SfxVersionTableDtor( const uno::Sequence < document::CmisVersion > & rInfo );
      76           0 :                             ~SfxVersionTableDtor()
      77           0 :                             { DelDtor(); }
      78             : 
      79             :     void                    DelDtor();
      80             : 
      81           0 :     size_t                  size() const
      82           0 :                             { return aTableList.size(); }
      83             : 
      84           0 :     SfxVersionInfo*         at( size_t i ) const
      85           0 :                             { return aTableList[ i ]; }
      86             : };
      87             : 
      88           0 : SfxVersionTableDtor::SfxVersionTableDtor( const uno::Sequence < util::RevisionTag >& rInfo )
      89             : {
      90           0 :     for ( sal_Int32 n=0; n<(sal_Int32)rInfo.getLength(); n++ )
      91             :     {
      92           0 :         SfxVersionInfo* pInfo = new SfxVersionInfo;
      93           0 :         pInfo->aName = rInfo[n].Identifier;
      94           0 :         pInfo->aComment = rInfo[n].Comment;
      95           0 :         pInfo->aAuthor = rInfo[n].Author;
      96             : 
      97           0 :         Date aDate ( rInfo[n].TimeStamp.Day,   rInfo[n].TimeStamp.Month,   rInfo[n].TimeStamp.Year );
      98           0 :         tools::Time aTime ( rInfo[n].TimeStamp.Hours, rInfo[n].TimeStamp.Minutes, rInfo[n].TimeStamp.Seconds, rInfo[n].TimeStamp.NanoSeconds );
      99             : 
     100           0 :         pInfo->aCreationDate = DateTime( aDate, aTime );
     101           0 :         aTableList.push_back( pInfo );
     102             :     }
     103           0 : }
     104             : 
     105           0 : SfxVersionTableDtor::SfxVersionTableDtor( const uno::Sequence < document::CmisVersion >& rInfo )
     106             : {
     107           0 :     for ( sal_Int32 n=0; n<(sal_Int32)rInfo.getLength(); n++ )
     108             :     {
     109           0 :         SfxVersionInfo* pInfo = new SfxVersionInfo;
     110           0 :         pInfo->aName = rInfo[n].Id;
     111           0 :         pInfo->aComment = rInfo[n].Comment;
     112           0 :         pInfo->aAuthor = rInfo[n].Author;
     113             : 
     114           0 :         Date aDate ( rInfo[n].TimeStamp.Day,   rInfo[n].TimeStamp.Month,   rInfo[n].TimeStamp.Year );
     115           0 :         tools::Time aTime ( rInfo[n].TimeStamp.Hours, rInfo[n].TimeStamp.Minutes, rInfo[n].TimeStamp.Seconds, rInfo[n].TimeStamp.NanoSeconds );
     116             : 
     117           0 :         pInfo->aCreationDate = DateTime( aDate, aTime );
     118           0 :         aTableList.push_back( pInfo );
     119             :     }
     120           0 : }
     121             : 
     122           0 : void SfxVersionTableDtor::DelDtor()
     123             : {
     124           0 :     for ( size_t i = 0, n = aTableList.size(); i < n; ++i )
     125           0 :         delete aTableList[ i ];
     126           0 :     aTableList.clear();
     127           0 : }
     128             : 
     129           0 : SfxVersionInfo::SfxVersionInfo()
     130           0 :     : aCreationDate( DateTime::EMPTY )
     131             : {
     132           0 : }
     133             : 
     134           0 : void SfxVersionsTabListBox_Impl::KeyInput(const KeyEvent& rKeyEvent)
     135             : {
     136           0 :     const vcl::KeyCode& rCode = rKeyEvent.GetKeyCode();
     137           0 :     switch (rCode.GetCode())
     138             :     {
     139             :         case KEY_RETURN :
     140             :         case KEY_ESCAPE :
     141             :         case KEY_TAB :
     142             :         {
     143           0 :             Dialog *pParent = GetParentDialog();
     144           0 :             if (pParent)
     145           0 :                 pParent->KeyInput(rKeyEvent);
     146             :             else
     147           0 :                 SvSimpleTable::KeyInput(rKeyEvent);
     148           0 :             break;
     149             :         }
     150             :         default:
     151           0 :             SvSimpleTable::KeyInput( rKeyEvent );
     152           0 :             break;
     153             :     }
     154           0 : }
     155             : 
     156           0 : void SfxVersionsTabListBox_Impl::Resize()
     157             : {
     158           0 :     SvSimpleTable::Resize();
     159           0 :     if (isInitialLayout(this))
     160           0 :         setColSizes();
     161           0 : }
     162             : 
     163           0 : void SfxVersionsTabListBox_Impl::setColSizes()
     164             : {
     165           0 :     HeaderBar &rBar = GetTheHeaderBar();
     166           0 :     if (rBar.GetItemCount() < 3)
     167           0 :         return;
     168             : 
     169             :     // recalculate the datetime column width
     170           0 :     long nWidestTime(GetTextWidth(getWidestTime(Application::GetSettings().GetLocaleDataWrapper())));
     171           0 :     long nW1 = rBar.GetTextWidth(rBar.GetItemText(1));
     172             : 
     173           0 :     long nMax = std::max(nWidestTime, nW1) + 12; // max width + a little offset
     174           0 :     const long nRest = GetSizePixel().Width() - nMax;
     175             : 
     176           0 :     std::set<OUString> aAuthors;
     177           0 :     SfxVersionInfo aInfo;
     178           0 :     aAuthors.insert(SvtUserOptions().GetFullName());
     179             : 
     180           0 :     for (SvTreeListEntry* pEntry = First(); pEntry; pEntry = Next(pEntry))
     181             :     {
     182           0 :         aAuthors.insert(((SfxVersionInfo*)pEntry->GetUserData())->aAuthor);
     183             :     }
     184             : 
     185           0 :     long nMaxAuthorWidth = nRest/4;
     186           0 :     for (std::set<OUString>::iterator aI = aAuthors.begin(), aEnd = aAuthors.end(); aI != aEnd; ++aI)
     187             :     {
     188           0 :         nMaxAuthorWidth = std::max(nMaxAuthorWidth, GetTextWidth(*aI));
     189           0 :         if (nMaxAuthorWidth > nRest/2)
     190             :         {
     191           0 :             nMaxAuthorWidth = nRest/2;
     192           0 :             break;
     193             :         }
     194             :     }
     195             : 
     196           0 :     long aStaticTabs[] = { 3, 0, 0, 0 };
     197           0 :     aStaticTabs[2] = nMax;
     198           0 :     aStaticTabs[3] = nMax + nMaxAuthorWidth;
     199           0 :     SvSimpleTable::SetTabs(aStaticTabs, MAP_PIXEL);
     200             : }
     201             : 
     202           0 : SfxVersionDialog::SfxVersionDialog ( SfxViewFrame* pVwFrame, bool bIsSaveVersionOnClose )
     203             :     : SfxModalDialog(NULL, "VersionsOfDialog", "sfx/ui/versionsofdialog.ui")
     204             :     , pViewFrame(pVwFrame)
     205             :     , m_pTable(NULL)
     206           0 :     , m_bIsSaveVersionOnClose(bIsSaveVersionOnClose)
     207             : {
     208           0 :     get(m_pSaveButton, "save");
     209           0 :     get(m_pSaveCheckBox, "always");
     210           0 :     get(m_pOpenButton, "open");
     211           0 :     get(m_pViewButton, "show");
     212           0 :     get(m_pDeleteButton, "delete");
     213           0 :     get(m_pCompareButton, "compare");
     214           0 :     get(m_pCmisButton, "cmis");
     215             : 
     216           0 :     SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("versions");
     217           0 :     Size aControlSize(260, 114);
     218           0 :     aControlSize = pContainer->LogicToPixel(aControlSize, MAP_APPFONT);
     219           0 :     pContainer->set_width_request(aControlSize.Width());
     220           0 :     pContainer->set_height_request(aControlSize.Height());
     221             : 
     222           0 :     m_pVersionBox = new SfxVersionsTabListBox_Impl(*pContainer, WB_TABSTOP);
     223             : 
     224           0 :     Link aClickLink = LINK( this, SfxVersionDialog, ButtonHdl_Impl );
     225           0 :     m_pViewButton->SetClickHdl ( aClickLink );
     226           0 :     m_pSaveButton->SetClickHdl ( aClickLink );
     227           0 :     m_pDeleteButton->SetClickHdl ( aClickLink );
     228           0 :     m_pCompareButton->SetClickHdl ( aClickLink );
     229           0 :     m_pOpenButton->SetClickHdl ( aClickLink );
     230           0 :     m_pSaveCheckBox->SetClickHdl ( aClickLink );
     231           0 :     m_pCmisButton->SetClickHdl ( aClickLink );
     232             : 
     233           0 :     m_pVersionBox->SetSelectHdl( LINK( this, SfxVersionDialog, SelectHdl_Impl ) );
     234           0 :     m_pVersionBox->SetDoubleClickHdl( LINK( this, SfxVersionDialog, DClickHdl_Impl ) );
     235             : 
     236           0 :     m_pVersionBox->GrabFocus();
     237           0 :     m_pVersionBox->SetStyle( m_pVersionBox->GetStyle() | WB_HSCROLL | WB_CLIPCHILDREN );
     238           0 :     m_pVersionBox->SetSelectionMode( SINGLE_SELECTION );
     239             : 
     240           0 :     long nTabs_Impl[] = { 3, 0, 0, 0 };
     241             : 
     242             : 
     243           0 :     m_pVersionBox->SvSimpleTable::SetTabs(&nTabs_Impl[0]);
     244           0 :     OUString sHeader1(get<FixedText>("datetime")->GetText());
     245           0 :     OUString sHeader2(get<FixedText>("savedby")->GetText());
     246           0 :     OUString sHeader3(get<FixedText>("comments")->GetText());
     247           0 :     OUStringBuffer sHeader;
     248           0 :     sHeader.append(sHeader1).append("\t").append(sHeader2)
     249           0 :         .append("\t ").append(sHeader3);
     250           0 :     m_pVersionBox->InsertHeaderEntry(sHeader.makeStringAndClear());
     251             : 
     252           0 :     HeaderBar &rBar = m_pVersionBox->GetTheHeaderBar();
     253           0 :     HeaderBarItemBits nBits = rBar.GetItemBits(1) | HIB_FIXEDPOS | HIB_FIXED;
     254           0 :     nBits &= ~HIB_CLICKABLE;
     255           0 :     rBar.SetItemBits(1, nBits);
     256           0 :     rBar.SetItemBits(2, nBits);
     257           0 :     rBar.SetItemBits(3, nBits);
     258             : 
     259           0 :     m_pVersionBox->Resize();       // OS: Hack for correct selection
     260             : 
     261             : 
     262             :     // set dialog title (filename or docinfo title)
     263           0 :     OUString sText = GetText();
     264           0 :     sText = sText + " " + pViewFrame->GetObjectShell()->GetTitle();
     265           0 :     SetText( sText );
     266             : 
     267           0 :     Init_Impl();
     268             : 
     269           0 :     m_pVersionBox->setColSizes();
     270           0 : }
     271             : 
     272           0 : OUString ConvertWhiteSpaces_Impl( const OUString& rText )
     273             : {
     274             :     // converted linebreaks and tabs to blanks; it's necessary for the display
     275           0 :     OUStringBuffer sConverted;
     276           0 :     const sal_Unicode* pChars = rText.getStr();
     277           0 :     while ( *pChars )
     278             :     {
     279           0 :         switch ( *pChars )
     280             :         {
     281             :             case '\n' :
     282             :             case '\t' :
     283           0 :                 sConverted.append(' ');
     284           0 :                 break;
     285             : 
     286             :             default:
     287           0 :                 sConverted.append(*pChars);
     288             :         }
     289             : 
     290           0 :         ++pChars;
     291             :     }
     292             : 
     293           0 :     return sConverted.makeStringAndClear();
     294             : }
     295             : 
     296           0 : void SfxVersionDialog::Init_Impl()
     297             : {
     298           0 :     SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
     299           0 :     SfxMedium* pMedium = pObjShell->GetMedium();
     300           0 :     uno::Sequence < util::RevisionTag > aVersions = pMedium->GetVersionList( true );
     301           0 :     delete m_pTable;
     302           0 :     m_pTable = new SfxVersionTableDtor( aVersions );
     303             :     {
     304           0 :         for ( size_t n = 0; n < m_pTable->size(); ++n )
     305             :         {
     306           0 :             SfxVersionInfo *pInfo = m_pTable->at( n );
     307           0 :             OUString aEntry = formatTime(pInfo->aCreationDate, Application::GetSettings().GetLocaleDataWrapper());
     308           0 :             aEntry += "\t";
     309           0 :             aEntry += pInfo->aAuthor;
     310           0 :             aEntry += "\t";
     311           0 :             aEntry += ConvertWhiteSpaces_Impl( pInfo->aComment );
     312           0 :             SvTreeListEntry *pEntry = m_pVersionBox->InsertEntry( aEntry );
     313           0 :             pEntry->SetUserData( pInfo );
     314           0 :         }
     315             :     }
     316             : 
     317           0 :     m_pSaveCheckBox->Check( m_bIsSaveVersionOnClose );
     318             : 
     319           0 :     bool bEnable = !pObjShell->IsReadOnly();
     320           0 :     m_pSaveButton->Enable( bEnable );
     321           0 :     m_pSaveCheckBox->Enable( bEnable );
     322             : 
     323           0 :     m_pOpenButton->Disable();
     324           0 :     m_pViewButton->Disable();
     325           0 :     m_pDeleteButton->Disable();
     326           0 :     m_pCompareButton->Disable();
     327             : 
     328           0 :     SvtMiscOptions miscOptions;
     329           0 :     if ( !miscOptions.IsExperimentalMode() )
     330           0 :         m_pCmisButton->Hide( );
     331           0 :     m_pCmisButton->Enable();
     332             : 
     333           0 :     SelectHdl_Impl(m_pVersionBox);
     334           0 : }
     335             : 
     336           0 : SfxVersionDialog::~SfxVersionDialog()
     337             : {
     338           0 :     delete m_pTable;
     339           0 :     delete m_pVersionBox;
     340           0 : }
     341             : 
     342           0 : void SfxVersionDialog::Open_Impl()
     343             : {
     344           0 :     SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
     345             : 
     346           0 :     SvTreeListEntry *pEntry = m_pVersionBox->FirstSelected();
     347           0 :     sal_uIntPtr nPos = m_pVersionBox->GetModel()->GetRelPos( pEntry );
     348           0 :     SfxInt16Item aItem( SID_VERSION, (short)nPos+1 );
     349           0 :     SfxStringItem aTarget( SID_TARGETNAME, "_blank" );
     350           0 :     SfxStringItem aReferer( SID_REFERER, "private:user" );
     351           0 :     SfxStringItem aFile( SID_FILE_NAME, pObjShell->GetMedium()->GetName() );
     352             : 
     353           0 :     uno::Sequence< beans::NamedValue > aEncryptionData;
     354           0 :     if ( GetEncryptionData_Impl( pObjShell->GetMedium()->GetItemSet(), aEncryptionData ) )
     355             :     {
     356             :         // there is a password, it should be used during the opening
     357           0 :         SfxUnoAnyItem aEncryptionDataItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) );
     358             :         pViewFrame->GetDispatcher()->Execute(
     359           0 :             SID_OPENDOC, SfxCallMode::ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, &aEncryptionDataItem, 0L );
     360             :     }
     361             :     else
     362             :         pViewFrame->GetDispatcher()->Execute(
     363           0 :             SID_OPENDOC, SfxCallMode::ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, 0L );
     364             : 
     365           0 :     Close();
     366           0 : }
     367             : 
     368           0 : IMPL_LINK_NOARG(SfxVersionDialog, DClickHdl_Impl)
     369             : {
     370           0 :     Open_Impl();
     371           0 :     return 0L;
     372             : }
     373             : 
     374           0 : IMPL_LINK_NOARG(SfxVersionDialog, SelectHdl_Impl)
     375             : {
     376           0 :     bool bEnable = ( m_pVersionBox->FirstSelected() != NULL );
     377           0 :     SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
     378           0 :     m_pDeleteButton->Enable(bEnable && !pObjShell->IsReadOnly());
     379           0 :     m_pOpenButton->Enable(bEnable);
     380           0 :     m_pViewButton->Enable(bEnable);
     381             : 
     382           0 :     const SfxPoolItem *pDummy=NULL;
     383           0 :     SfxItemState eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_MERGE, pDummy );
     384           0 :     eState = pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_COMPARE, pDummy );
     385           0 :     m_pCompareButton->Enable(bEnable && eState >= SfxItemState::DEFAULT);
     386             : 
     387           0 :     return 0L;
     388             : }
     389             : 
     390           0 : IMPL_LINK( SfxVersionDialog, ButtonHdl_Impl, Button*, pButton )
     391             : {
     392           0 :     SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
     393           0 :     SvTreeListEntry *pEntry = m_pVersionBox->FirstSelected();
     394             : 
     395           0 :     if (pButton == m_pSaveCheckBox)
     396             :     {
     397           0 :         m_bIsSaveVersionOnClose = m_pSaveCheckBox->IsChecked();
     398             :     }
     399           0 :     else if (pButton == m_pSaveButton)
     400             :     {
     401           0 :         SfxVersionInfo aInfo;
     402           0 :         aInfo.aAuthor = SvtUserOptions().GetFullName();
     403           0 :         boost::scoped_ptr<SfxViewVersionDialog_Impl> pDlg(new SfxViewVersionDialog_Impl(this, aInfo, true));
     404           0 :         short nRet = pDlg->Execute();
     405           0 :         if ( nRet == RET_OK )
     406             :         {
     407           0 :             SfxStringItem aComment( SID_DOCINFO_COMMENTS, aInfo.aComment );
     408           0 :             pObjShell->SetModified( true );
     409             :             const SfxPoolItem* aItems[2];
     410           0 :             aItems[0] = &aComment;
     411           0 :             aItems[1] = NULL;
     412           0 :             pViewFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, aItems, 0 );
     413           0 :             m_pVersionBox->SetUpdateMode( false );
     414           0 :             m_pVersionBox->Clear();
     415           0 :             Init_Impl();
     416           0 :             m_pVersionBox->SetUpdateMode( true );
     417           0 :         }
     418             :     }
     419           0 :     if (pButton == m_pDeleteButton && pEntry)
     420             :     {
     421           0 :         pObjShell->GetMedium()->RemoveVersion_Impl( ((SfxVersionInfo*) pEntry->GetUserData())->aName );
     422           0 :         pObjShell->SetModified( true );
     423           0 :         m_pVersionBox->SetUpdateMode( false );
     424           0 :         m_pVersionBox->Clear();
     425           0 :         Init_Impl();
     426           0 :         m_pVersionBox->SetUpdateMode( true );
     427             :     }
     428           0 :     else if (pButton == m_pOpenButton && pEntry)
     429             :     {
     430           0 :         Open_Impl();
     431             :     }
     432           0 :     else if (pButton == m_pViewButton && pEntry)
     433             :     {
     434           0 :         SfxVersionInfo* pInfo = (SfxVersionInfo*) pEntry->GetUserData();
     435           0 :         boost::scoped_ptr<SfxViewVersionDialog_Impl> pDlg(new SfxViewVersionDialog_Impl(this, *pInfo, false));
     436           0 :         pDlg->Execute();
     437             :     }
     438           0 :     else if (pEntry && pButton == m_pCompareButton)
     439             :     {
     440           0 :         SfxAllItemSet aSet( pObjShell->GetPool() );
     441           0 :         sal_uIntPtr nPos = m_pVersionBox->GetModel()->GetRelPos( pEntry );
     442           0 :         aSet.Put( SfxInt16Item( SID_VERSION, (short)nPos+1 ) );
     443           0 :         aSet.Put( SfxStringItem( SID_FILE_NAME, pObjShell->GetMedium()->GetName() ) );
     444             : 
     445           0 :         SfxItemSet* pSet = pObjShell->GetMedium()->GetItemSet();
     446           0 :         SFX_ITEMSET_ARG( pSet, pFilterItem, SfxStringItem, SID_FILTER_NAME, false );
     447           0 :         SFX_ITEMSET_ARG( pSet, pFilterOptItem, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
     448           0 :         if ( pFilterItem )
     449           0 :             aSet.Put( *pFilterItem );
     450           0 :         if ( pFilterOptItem )
     451           0 :             aSet.Put( *pFilterOptItem );
     452             : 
     453           0 :         pViewFrame->GetDispatcher()->Execute( SID_DOCUMENT_COMPARE, SfxCallMode::ASYNCHRON, aSet );
     454           0 :         Close();
     455             :     }
     456           0 :     else if (pButton == m_pCmisButton)
     457             :     {
     458           0 :         boost::scoped_ptr<SfxCmisVersionsDialog> pDlg(new SfxCmisVersionsDialog(pViewFrame, false));
     459           0 :         pDlg->Execute();
     460             :     }
     461             : 
     462           0 :     return 0L;
     463             : }
     464             : 
     465           0 : SfxViewVersionDialog_Impl::SfxViewVersionDialog_Impl(vcl::Window *pParent, SfxVersionInfo& rInfo, bool bEdit)
     466             :     : SfxModalDialog(pParent, "VersionCommentDialog", "sfx/ui/versioncommentdialog.ui")
     467           0 :     , m_rInfo(rInfo)
     468             : {
     469           0 :     get(m_pDateTimeText, "timestamp");
     470           0 :     get(m_pSavedByText, "author");
     471           0 :     get(m_pEdit, "textview");
     472           0 :     get(m_pOKButton, "ok");
     473           0 :     get(m_pCancelButton, "cancel");
     474           0 :     get(m_pCloseButton, "close");
     475             : 
     476           0 :     const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
     477           0 :     m_pDateTimeText->SetText(m_pDateTimeText->GetText() + formatTime(rInfo.aCreationDate, rLocaleWrapper));
     478           0 :     m_pSavedByText->SetText(m_pSavedByText->GetText() + rInfo.aAuthor);
     479           0 :     m_pEdit->SetText(rInfo.aComment);
     480           0 :     m_pEdit->set_height_request(7 * m_pEdit->GetTextHeight());
     481           0 :     m_pEdit->set_width_request(40 * m_pEdit->approximate_char_width());
     482           0 :     m_pOKButton->SetClickHdl(LINK(this, SfxViewVersionDialog_Impl, ButtonHdl));
     483             : 
     484           0 :     if (!bEdit)
     485             :     {
     486           0 :         m_pOKButton->Hide();
     487           0 :         m_pCancelButton->Hide();
     488           0 :         m_pEdit->SetReadOnly(true);
     489           0 :         SetText(SfxResId(STR_VIEWVERSIONCOMMENT));
     490           0 :         m_pCloseButton->GrabFocus();
     491             :     }
     492             :     else
     493             :     {
     494           0 :         m_pDateTimeText->Hide();
     495           0 :         m_pCloseButton->Hide();
     496           0 :         m_pEdit->GrabFocus();
     497             :     }
     498           0 : }
     499             : 
     500           0 : IMPL_LINK(SfxViewVersionDialog_Impl, ButtonHdl, Button*, pButton)
     501             : {
     502             :     assert(pButton == m_pOKButton);
     503             :     (void)pButton;
     504           0 :     m_rInfo.aComment = m_pEdit->GetText();
     505           0 :     EndDialog(RET_OK);
     506           0 :     return 0L;
     507             : }
     508             : 
     509           0 : SfxCmisVersionsDialog::SfxCmisVersionsDialog ( SfxViewFrame* pVwFrame, bool bIsSaveVersionOnClose )
     510             :     : SfxModalDialog(NULL, "VersionsCmisDialog", "sfx/ui/versionscmis.ui")
     511             :     , pViewFrame(pVwFrame)
     512             :     , m_pTable(NULL)
     513           0 :     , m_bIsSaveVersionOnClose(bIsSaveVersionOnClose)
     514             : {
     515           0 :     get(m_pOpenButton, "open");
     516           0 :     get(m_pViewButton, "show");
     517           0 :     get(m_pDeleteButton, "delete");
     518           0 :     get(m_pCompareButton, "compare");
     519             : 
     520           0 :     SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("versions");
     521           0 :     Size aControlSize(260, 114);
     522           0 :     aControlSize = pContainer->LogicToPixel(aControlSize, MAP_APPFONT);
     523           0 :     pContainer->set_width_request(aControlSize.Width());
     524           0 :     pContainer->set_height_request(aControlSize.Height());
     525             : 
     526           0 :     m_pVersionBox = new SfxVersionsTabListBox_Impl(*pContainer, WB_TABSTOP);
     527             : 
     528           0 :     m_pVersionBox->GrabFocus();
     529           0 :     m_pVersionBox->SetStyle( m_pVersionBox->GetStyle() | WB_HSCROLL | WB_CLIPCHILDREN );
     530           0 :     m_pVersionBox->SetSelectionMode( SINGLE_SELECTION );
     531             : 
     532           0 :     long nTabs_Impl[] = { 3, 0, 0, 0 };
     533             : 
     534           0 :     m_pVersionBox->SvSimpleTable::SetTabs(&nTabs_Impl[0]);
     535           0 :     OUString sHeader1(get<FixedText>("datetime")->GetText());
     536           0 :     OUString sHeader2(get<FixedText>("savedby")->GetText());
     537           0 :     OUString sHeader3(get<FixedText>("comments")->GetText());
     538           0 :     OUStringBuffer sHeader;
     539           0 :     sHeader.append(sHeader1).append("\t").append(sHeader2)
     540           0 :         .append("\t ").append(sHeader3);
     541           0 :     m_pVersionBox->InsertHeaderEntry(sHeader.makeStringAndClear());
     542             : 
     543           0 :     HeaderBar &rBar = m_pVersionBox->GetTheHeaderBar();
     544           0 :     HeaderBarItemBits nBits = rBar.GetItemBits(1) | HIB_FIXEDPOS | HIB_FIXED;
     545           0 :     nBits &= ~HIB_CLICKABLE;
     546           0 :     rBar.SetItemBits(1, nBits);
     547           0 :     rBar.SetItemBits(2, nBits);
     548           0 :     rBar.SetItemBits(3, nBits);
     549             : 
     550           0 :     m_pVersionBox->Resize();
     551             : 
     552           0 :     OUString sText = GetText();
     553           0 :     sText = sText + " " + pViewFrame->GetObjectShell()->GetTitle();
     554           0 :     SetText( sText );
     555             : 
     556           0 :     LoadVersions();
     557             : 
     558           0 :     m_pVersionBox->setColSizes();
     559             : 
     560           0 : }
     561             : 
     562           0 : SfxCmisVersionsDialog::~SfxCmisVersionsDialog()
     563             : {
     564           0 :     delete m_pTable;
     565           0 :     delete m_pVersionBox;
     566           0 : }
     567             : 
     568           0 : void SfxCmisVersionsDialog::LoadVersions()
     569             : {
     570           0 :     SfxObjectShell *pObjShell = pViewFrame->GetObjectShell();
     571           0 :     uno::Sequence < document::CmisVersion > aVersions = pObjShell->GetCmisVersions( );
     572           0 :     delete m_pTable;
     573           0 :     m_pTable = new SfxVersionTableDtor( aVersions );
     574             :     {
     575           0 :         for ( size_t n = 0; n < m_pTable->size(); ++n )
     576             :         {
     577           0 :             SfxVersionInfo *pInfo = m_pTable->at( n );
     578           0 :             OUString aEntry = formatTime(pInfo->aCreationDate, Application::GetSettings().GetLocaleDataWrapper());
     579           0 :             aEntry += "\t";
     580           0 :             aEntry += pInfo->aAuthor;
     581           0 :             aEntry += "\t";
     582           0 :             aEntry += ConvertWhiteSpaces_Impl( pInfo->aComment );
     583           0 :             SvTreeListEntry *pEntry = m_pVersionBox->InsertEntry( aEntry );
     584           0 :             pEntry->SetUserData( pInfo );
     585           0 :         }
     586           0 :     }
     587             : 
     588         951 : }
     589             : 
     590             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10