1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "srchdlg.hxx"
22 #include <comphelper/string.hxx>
23 #include <sfx2/sfxresid.hxx>
24 #include <sfx2/sfxuno.hxx>
27 #include <tools/debug.hxx>
28 #include <unotools/viewoptions.hxx>
30 using namespace ::com::sun::star::uno
;
36 #define MAX_SAVE_COUNT (sal_uInt16)10
42 SearchDialog::SearchDialog(vcl::Window
* pWindow
, const OUString
& rConfigName
)
43 : ModelessDialog(pWindow
, "SearchDialog", "sfx/ui/searchdialog.ui")
44 , m_sConfigName(rConfigName
)
45 , m_bIsConstructed(false)
48 get(m_pSearchEdit
, "searchterm");
49 get(m_pWholeWordsBox
, "wholewords");
50 get(m_pMatchCaseBox
, "matchcase");
51 get(m_pWrapAroundBox
, "wrap");
52 get(m_pBackwardsBox
, "backwards");
53 get(m_pFindBtn
, "search");
56 m_pFindBtn
->SetClickHdl( LINK( this, SearchDialog
, FindHdl
) );
57 // load config: old search strings and the status of the check boxes
59 // the search edit should have the focus
60 m_pSearchEdit
->GrabFocus();
63 SearchDialog::~SearchDialog()
68 void SearchDialog::dispose()
71 m_aCloseHdl
.Call( NULL
);
72 m_pSearchEdit
.clear();
73 m_pWholeWordsBox
.clear();
74 m_pMatchCaseBox
.clear();
75 m_pWrapAroundBox
.clear();
76 m_pBackwardsBox
.clear();
78 ModelessDialog::dispose();
81 void SearchDialog::LoadConfig()
83 SvtViewOptions
aViewOpt( E_DIALOG
, m_sConfigName
);
84 if ( aViewOpt
.Exists() )
86 m_sWinState
= OUStringToOString(aViewOpt
.GetWindowState(), RTL_TEXTENCODING_ASCII_US
);
87 Any aUserItem
= aViewOpt
.GetUserItem( "UserItem" );
89 if ( aUserItem
>>= aTemp
)
91 OUString
sUserData( aTemp
);
92 DBG_ASSERT( comphelper::string::getTokenCount(sUserData
, ';') == 5, "invalid config data" );
94 OUString sSearchText
= sUserData
.getToken( 0, ';', nIdx
);
95 m_pWholeWordsBox
->Check( sUserData
.getToken( 0, ';', nIdx
).toInt32() == 1 );
96 m_pMatchCaseBox
->Check( sUserData
.getToken( 0, ';', nIdx
).toInt32() == 1 );
97 m_pWrapAroundBox
->Check( sUserData
.getToken( 0, ';', nIdx
).toInt32() == 1 );
98 m_pBackwardsBox
->Check( sUserData
.getToken( 0, ';', nIdx
).toInt32() == 1 );
102 m_pSearchEdit
->InsertEntry( sSearchText
.getToken( 0, '\t', nIdx
) );
103 m_pSearchEdit
->SelectEntryPos(0);
107 m_pWrapAroundBox
->Check( true );
110 void SearchDialog::SaveConfig()
112 SvtViewOptions
aViewOpt( E_DIALOG
, m_sConfigName
);
113 aViewOpt
.SetWindowState(OStringToOUString(m_sWinState
, RTL_TEXTENCODING_ASCII_US
));
115 sal_Int32 i
= 0, nCount
= std::min( m_pSearchEdit
->GetEntryCount(), static_cast<sal_Int32
>(MAX_SAVE_COUNT
) );
116 for ( ; i
< nCount
; ++i
)
118 sUserData
+= m_pSearchEdit
->GetEntry(i
);
121 sUserData
= comphelper::string::stripStart(sUserData
, '\t');
123 sUserData
+= OUString::number( m_pWholeWordsBox
->IsChecked() ? 1 : 0 );
125 sUserData
+= OUString::number( m_pMatchCaseBox
->IsChecked() ? 1 : 0 );
127 sUserData
+= OUString::number( m_pWrapAroundBox
->IsChecked() ? 1 : 0 );
129 sUserData
+= OUString::number( m_pBackwardsBox
->IsChecked() ? 1 : 0 );
131 Any aUserItem
= makeAny( OUString( sUserData
) );
132 aViewOpt
.SetUserItem( "UserItem", aUserItem
);
135 IMPL_LINK_NOARG(SearchDialog
, FindHdl
)
137 OUString sSrchTxt
= m_pSearchEdit
->GetText();
138 sal_Int32 nPos
= m_pSearchEdit
->GetEntryPos( sSrchTxt
);
139 if ( nPos
> 0 && nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
140 m_pSearchEdit
->RemoveEntryAt(nPos
);
142 m_pSearchEdit
->InsertEntry( sSrchTxt
, 0 );
143 m_aFindHdl
.Call( this );
147 void SearchDialog::SetFocusOnEdit()
149 Selection
aSelection( 0, m_pSearchEdit
->GetText().getLength() );
150 m_pSearchEdit
->SetSelection( aSelection
);
151 m_pSearchEdit
->GrabFocus();
154 bool SearchDialog::Close()
156 bool bRet
= ModelessDialog::Close();
157 m_aCloseHdl
.Call( this );
161 void SearchDialog::StateChanged( StateChangedType nStateChange
)
163 if ( nStateChange
== StateChangedType::InitShow
)
165 if (!m_sWinState
.isEmpty())
166 SetWindowState( m_sWinState
);
167 m_bIsConstructed
= true;
170 ModelessDialog::StateChanged( nStateChange
);
173 void SearchDialog::Move()
175 ModelessDialog::Move();
176 if ( m_bIsConstructed
&& IsReallyVisible() )
177 m_sWinState
= GetWindowState( WINDOWSTATE_MASK_POS
| WINDOWSTATE_MASK_STATE
);
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */