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

Generated by: LCOV version 1.10