LCOV - code coverage report
Current view: top level - cui/source/dialogs - postdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 110 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 17 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 <tools/date.hxx>
      21             : #include <tools/time.hxx>
      22             : #include <vcl/svapp.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <vcl/settings.hxx>
      25             : #include <svl/itempool.hxx>
      26             : #include <svl/itemset.hxx>
      27             : #include <unotools/useroptions.hxx>
      28             : #include <unotools/localedatawrapper.hxx>
      29             : #include <comphelper/processfactory.hxx>
      30             : #include <svx/svxids.hrc>
      31             : 
      32             : #include <cuires.hrc>
      33             : #include <svx/postattr.hxx>
      34             : #include "postdlg.hxx"
      35             : #include <dialmgr.hxx>
      36             : 
      37             : #include "helpid.hrc"
      38             : 
      39             : // class SvxPostItDialog -------------------------------------------------
      40             : 
      41           0 : SvxPostItDialog::SvxPostItDialog(vcl::Window* pParent, const SfxItemSet& rCoreSet,
      42             :     bool bPrevNext)
      43             :     : SfxModalDialog(pParent, "CommentDialog", "cui/ui/comment.ui")
      44             :     , rSet(rCoreSet)
      45           0 :     , pOutSet(0)
      46             : {
      47           0 :     get(m_pLastEditFT, "lastedit");
      48           0 :     get(m_pInsertAuthor, "insertauthor");
      49           0 :     get(m_pAuthorBtn, "author");
      50           0 :     get(m_pOKBtn, "ok");
      51           0 :     get(m_pPrevBtn, "previous");
      52           0 :     get(m_pNextBtn, "next");
      53           0 :     get(m_pEditED, "edit");
      54             : 
      55           0 :     m_pPrevBtn->SetClickHdl( LINK( this, SvxPostItDialog, PrevHdl ) );
      56           0 :     m_pNextBtn->SetClickHdl( LINK( this, SvxPostItDialog, NextHdl ) );
      57           0 :     m_pAuthorBtn->SetClickHdl( LINK( this, SvxPostItDialog, Stamp ) );
      58           0 :     m_pOKBtn->SetClickHdl( LINK( this, SvxPostItDialog, OKHdl ) );
      59             : 
      60           0 :     vcl::Font aFont( m_pEditED->GetFont() );
      61           0 :     aFont.SetWeight( WEIGHT_LIGHT );
      62           0 :     m_pEditED->SetFont( aFont );
      63             : 
      64           0 :     bool bNew = true;
      65           0 :     sal_uInt16 nWhich = 0;
      66             : 
      67           0 :     if ( !bPrevNext )
      68             :     {
      69           0 :         m_pPrevBtn->Hide();
      70           0 :         m_pNextBtn->Hide();
      71             :     }
      72             : 
      73           0 :     nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR );
      74           0 :     OUString aAuthorStr, aDateStr;
      75             : 
      76           0 :     if ( rSet.GetItemState( nWhich, true ) >= SfxItemState::DEFAULT )
      77             :     {
      78           0 :         bNew = false;
      79             :         const SvxPostItAuthorItem& rAuthor =
      80           0 :             static_cast<const SvxPostItAuthorItem&>(rSet.Get( nWhich ));
      81           0 :         aAuthorStr = rAuthor.GetValue();
      82             :     }
      83             :     else
      84           0 :         aAuthorStr = SvtUserOptions().GetID();
      85             : 
      86           0 :     nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE );
      87             : 
      88           0 :     if ( rSet.GetItemState( nWhich, true ) >= SfxItemState::DEFAULT )
      89             :     {
      90             :         const SvxPostItDateItem& rDate =
      91           0 :             static_cast<const SvxPostItDateItem&>(rSet.Get( nWhich ));
      92           0 :         aDateStr = rDate.GetValue();
      93             :     }
      94             :     else
      95             :     {
      96           0 :         const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
      97           0 :         aDateStr = rLocaleWrapper.getDate( Date( Date::SYSTEM ) );
      98             :     }
      99             : 
     100           0 :     nWhich = rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT );
     101             : 
     102           0 :     OUString aTextStr;
     103           0 :     if ( rSet.GetItemState( nWhich, true ) >= SfxItemState::DEFAULT )
     104             :     {
     105             :         const SvxPostItTextItem& rText =
     106           0 :             static_cast<const SvxPostItTextItem&>(rSet.Get( nWhich ));
     107           0 :         aTextStr = rText.GetValue();
     108             :     }
     109             : 
     110           0 :     ShowLastAuthor(aAuthorStr, aDateStr);
     111             : 
     112             :     //lock to initial .ui placeholder size before replacing contents
     113           0 :     Size aSize(m_pEditED->get_preferred_size());
     114           0 :     m_pEditED->set_width_request(aSize.Width());
     115           0 :     m_pEditED->set_height_request(aSize.Height());
     116             : 
     117           0 :     m_pEditED->SetText(convertLineEnd(aTextStr, GetSystemLineEnd()));
     118             : 
     119           0 :     if (!bNew)
     120           0 :         SetText( get<FixedText>("alttitle")->GetText() );
     121           0 : }
     122             : 
     123             : 
     124             : 
     125           0 : SvxPostItDialog::~SvxPostItDialog()
     126             : {
     127           0 :     disposeOnce();
     128           0 : }
     129             : 
     130           0 : void SvxPostItDialog::dispose()
     131             : {
     132           0 :     delete pOutSet;
     133           0 :     pOutSet = 0;
     134           0 :     m_pLastEditFT.clear();
     135           0 :     m_pEditED.clear();
     136           0 :     m_pInsertAuthor.clear();
     137           0 :     m_pAuthorBtn.clear();
     138           0 :     m_pOKBtn.clear();
     139           0 :     m_pPrevBtn.clear();
     140           0 :     m_pNextBtn.clear();
     141           0 :     SfxModalDialog::dispose();
     142           0 : }
     143             : 
     144             : 
     145             : 
     146           0 : void SvxPostItDialog::ShowLastAuthor(const OUString& rAuthor, const OUString& rDate)
     147             : {
     148           0 :     OUString sTxt( rAuthor );
     149           0 :     sTxt += ", ";
     150           0 :     sTxt += rDate;
     151           0 :     m_pLastEditFT->SetText( sTxt );
     152           0 : }
     153             : 
     154             : 
     155             : 
     156           0 : const sal_uInt16* SvxPostItDialog::GetRanges()
     157             : {
     158             :     static const sal_uInt16 pRanges[] =
     159             :     {
     160             :         SID_ATTR_POSTIT_AUTHOR,
     161             :         SID_ATTR_POSTIT_TEXT,
     162             :         0
     163             :     };
     164           0 :     return pRanges;
     165             : }
     166             : 
     167             : 
     168             : 
     169           0 : void SvxPostItDialog::EnableTravel(bool bNext, bool bPrev)
     170             : {
     171           0 :     m_pPrevBtn->Enable(bPrev);
     172           0 :     m_pNextBtn->Enable(bNext);
     173           0 : }
     174             : 
     175             : 
     176             : 
     177           0 : IMPL_LINK_NOARG(SvxPostItDialog, PrevHdl)
     178             : {
     179           0 :     aPrevHdlLink.Call( this );
     180           0 :     return 0;
     181             : }
     182             : 
     183           0 : IMPL_LINK_NOARG(SvxPostItDialog, NextHdl)
     184             : {
     185           0 :     aNextHdlLink.Call( this );
     186           0 :     return 0;
     187             : }
     188             : 
     189           0 : IMPL_LINK_NOARG(SvxPostItDialog, Stamp)
     190             : {
     191           0 :     Date aDate( Date::SYSTEM );
     192           0 :     tools::Time aTime( tools::Time::SYSTEM );
     193           0 :     OUString aTmp( SvtUserOptions().GetID() );
     194           0 :     const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
     195           0 :     OUString aStr( m_pEditED->GetText() );
     196           0 :     aStr += "\n---- ";
     197             : 
     198           0 :     if ( !aTmp.isEmpty() )
     199             :     {
     200           0 :         aStr += aTmp;
     201           0 :         aStr += ", ";
     202             :     }
     203           0 :     aStr += rLocaleWrapper.getDate(aDate);
     204           0 :     aStr += ", ";
     205           0 :     aStr += rLocaleWrapper.getTime(aTime, false, false);
     206           0 :     aStr += " ----\n";
     207             : 
     208           0 :     aStr = convertLineEnd(aStr, GetSystemLineEnd());
     209             : 
     210           0 :     m_pEditED->SetText(aStr);
     211           0 :     sal_Int32 nLen = aStr.getLength();
     212           0 :     m_pEditED->GrabFocus();
     213           0 :     m_pEditED->SetSelection( Selection( nLen, nLen ) );
     214           0 :     return 0;
     215             : }
     216             : 
     217             : 
     218             : 
     219           0 : IMPL_LINK_NOARG(SvxPostItDialog, OKHdl)
     220             : {
     221           0 :     const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
     222           0 :     pOutSet = new SfxItemSet( rSet );
     223             :     pOutSet->Put( SvxPostItAuthorItem( SvtUserOptions().GetID(),
     224           0 :                                          rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_AUTHOR ) ) );
     225             :     pOutSet->Put( SvxPostItDateItem( rLocaleWrapper.getDate( Date( Date::SYSTEM ) ),
     226           0 :                                      rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_DATE ) ) );
     227           0 :     pOutSet->Put( SvxPostItTextItem( m_pEditED->GetText(),
     228           0 :                                      rSet.GetPool()->GetWhich( SID_ATTR_POSTIT_TEXT ) ) );
     229           0 :     EndDialog( RET_OK );
     230           0 :     return 0;
     231           0 : }
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11