LCOV - code coverage report
Current view: top level - sfx2/source/dialog - srchdlg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 87 0.0 %
Date: 2014-04-14 Functions: 0 11 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             : 
      21             : #include "srchdlg.hxx"
      22             : #include <comphelper/string.hxx>
      23             : #include <sfx2/sfxresid.hxx>
      24             : #include <sfx2/sfxuno.hxx>
      25             : 
      26             : #include "dialog.hrc"
      27             : #include <tools/debug.hxx>
      28             : #include <unotools/viewoptions.hxx>
      29             : 
      30             : using namespace ::com::sun::star::uno;
      31             : 
      32             : 
      33             : 
      34             : namespace sfx2 {
      35             : 
      36             : #define MAX_SAVE_COUNT      (sal_uInt16)10
      37             : 
      38             : 
      39             : // SearchDialog
      40             : 
      41             : 
      42           0 : SearchDialog::SearchDialog(Window* pWindow, const OUString& rConfigName)
      43             :     : ModelessDialog(pWindow, "SearchDialog", "sfx/ui/searchdialog.ui")
      44             :     , m_sConfigName(rConfigName)
      45           0 :     , m_bIsConstructed(false)
      46             : 
      47             : {
      48           0 :     get(m_pSearchEdit, "searchterm");
      49           0 :     get(m_pWholeWordsBox, "wholewords");
      50           0 :     get(m_pMatchCaseBox, "matchcase");
      51           0 :     get(m_pWrapAroundBox, "wrap");
      52           0 :     get(m_pBackwardsBox, "backwards");
      53           0 :     get(m_pFindBtn, "search");
      54             : 
      55             :     // set handler
      56           0 :     m_pFindBtn->SetClickHdl( LINK( this, SearchDialog, FindHdl ) );
      57             :     // load config: old search strings and the status of the check boxes
      58           0 :     LoadConfig();
      59             :     // the search edit should have the focus
      60           0 :     m_pSearchEdit->GrabFocus();
      61           0 : }
      62             : 
      63           0 : SearchDialog::~SearchDialog()
      64             : {
      65           0 :     SaveConfig();
      66           0 :     m_aCloseHdl.Call( NULL );
      67           0 : }
      68             : 
      69           0 : void SearchDialog::LoadConfig()
      70             : {
      71           0 :     SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
      72           0 :     if ( aViewOpt.Exists() )
      73             :     {
      74           0 :         m_sWinState = OUStringToOString(aViewOpt.GetWindowState(), RTL_TEXTENCODING_ASCII_US);
      75           0 :         Any aUserItem = aViewOpt.GetUserItem( "UserItem" );
      76           0 :         OUString aTemp;
      77           0 :         if ( aUserItem >>= aTemp )
      78             :         {
      79           0 :             OUString sUserData( aTemp );
      80             :             DBG_ASSERT( comphelper::string::getTokenCount(sUserData, ';') == 5, "invalid config data" );
      81           0 :             sal_Int32 nIdx = 0;
      82           0 :             OUString sSearchText = sUserData.getToken( 0, ';', nIdx );
      83           0 :             m_pWholeWordsBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
      84           0 :             m_pMatchCaseBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
      85           0 :             m_pWrapAroundBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
      86           0 :             m_pBackwardsBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
      87             : 
      88           0 :             nIdx = 0;
      89           0 :             while ( nIdx != -1 )
      90           0 :                 m_pSearchEdit->InsertEntry( sSearchText.getToken( 0, '\t', nIdx ) );
      91           0 :             m_pSearchEdit->SelectEntryPos(0);
      92           0 :         }
      93             :     }
      94             :     else
      95           0 :         m_pWrapAroundBox->Check( true );
      96           0 : }
      97             : 
      98           0 : void SearchDialog::SaveConfig()
      99             : {
     100           0 :     SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
     101           0 :     aViewOpt.SetWindowState(OStringToOUString(m_sWinState, RTL_TEXTENCODING_ASCII_US));
     102           0 :     OUString sUserData;
     103           0 :     sal_Int32 i = 0, nCount = std::min( m_pSearchEdit->GetEntryCount(), static_cast<sal_Int32>(MAX_SAVE_COUNT) );
     104           0 :     for ( ; i < nCount; ++i )
     105             :     {
     106           0 :         sUserData += m_pSearchEdit->GetEntry(i);
     107           0 :         sUserData += "\t";
     108             :     }
     109           0 :     sUserData = comphelper::string::stripStart(sUserData, '\t');
     110           0 :     sUserData += ";";
     111           0 :     sUserData += OUString::number( m_pWholeWordsBox->IsChecked() ? 1 : 0 );
     112           0 :     sUserData += ";";
     113           0 :     sUserData += OUString::number( m_pMatchCaseBox->IsChecked() ? 1 : 0 );
     114           0 :     sUserData += ";";
     115           0 :     sUserData += OUString::number( m_pWrapAroundBox->IsChecked() ? 1 : 0 );
     116           0 :     sUserData += ";";
     117           0 :     sUserData += OUString::number( m_pBackwardsBox->IsChecked() ? 1 : 0 );
     118             : 
     119           0 :     Any aUserItem = makeAny( OUString( sUserData ) );
     120           0 :     aViewOpt.SetUserItem( "UserItem", aUserItem );
     121           0 : }
     122             : 
     123           0 : IMPL_LINK_NOARG(SearchDialog, FindHdl)
     124             : {
     125           0 :     OUString sSrchTxt = m_pSearchEdit->GetText();
     126           0 :     sal_Int32 nPos = m_pSearchEdit->GetEntryPos( sSrchTxt );
     127           0 :     if ( nPos > 0 && nPos != COMBOBOX_ENTRY_NOTFOUND )
     128           0 :         m_pSearchEdit->RemoveEntryAt(nPos);
     129           0 :     if ( nPos > 0 )
     130           0 :         m_pSearchEdit->InsertEntry( sSrchTxt, 0 );
     131           0 :     m_aFindHdl.Call( this );
     132           0 :     return 0;
     133             : }
     134             : 
     135           0 : void SearchDialog::SetFocusOnEdit()
     136             : {
     137           0 :     Selection aSelection( 0, m_pSearchEdit->GetText().getLength() );
     138           0 :     m_pSearchEdit->SetSelection( aSelection );
     139           0 :     m_pSearchEdit->GrabFocus();
     140           0 : }
     141             : 
     142           0 : bool SearchDialog::Close()
     143             : {
     144           0 :     bool bRet = ModelessDialog::Close();
     145           0 :     m_aCloseHdl.Call( this );
     146           0 :     return bRet;
     147             : }
     148             : 
     149           0 : void SearchDialog::StateChanged( StateChangedType nStateChange )
     150             : {
     151           0 :     if ( nStateChange == STATE_CHANGE_INITSHOW )
     152             :     {
     153           0 :         if (!m_sWinState.isEmpty())
     154           0 :             SetWindowState( m_sWinState );
     155           0 :         m_bIsConstructed = true;
     156             :     }
     157             : 
     158           0 :     ModelessDialog::StateChanged( nStateChange );
     159           0 : }
     160             : 
     161           0 : void SearchDialog::Move()
     162             : {
     163           0 :     ModelessDialog::Move();
     164           0 :     if ( m_bIsConstructed && IsReallyVisible() )
     165           0 :         m_sWinState = GetWindowState( WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE );
     166           0 : }
     167             : 
     168             : 
     169             : 
     170             : } // namespace sfx2
     171             : 
     172             : 
     173             : 
     174             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10