Branch data 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 "srchdlg.hrc"
27 : : #include "dialog.hrc"
28 : : #include <tools/debug.hxx>
29 : : #include <unotools/viewoptions.hxx>
30 : :
31 : : using namespace ::com::sun::star::uno;
32 : :
33 : : // ============================================================================
34 : :
35 : : namespace sfx2 {
36 : :
37 : : #define USERITEM_NAME DEFINE_CONST_OUSTRING("UserItem")
38 : : #define MAX_SAVE_COUNT (sal_uInt16)10
39 : :
40 : : // ============================================================================
41 : : // SearchDialog
42 : : // ============================================================================
43 : :
44 : 0 : SearchDialog::SearchDialog( Window* pWindow, const ::rtl::OUString& rConfigName ) :
45 : :
46 : : ModelessDialog( pWindow, SfxResId( RID_DLG_SEARCH ) ),
47 : :
48 : : m_aSearchLabel ( this, SfxResId( FT_SEARCH ) ),
49 : : m_aSearchEdit ( this, SfxResId( ED_SEARCH ) ),
50 : : m_aWholeWordsBox ( this, SfxResId( CB_WHOLEWORDS ) ),
51 : : m_aMatchCaseBox ( this, SfxResId( CB_MATCHCASE ) ),
52 : : m_aWrapAroundBox ( this, SfxResId( CB_WRAPAROUND ) ),
53 : : m_aBackwardsBox ( this, SfxResId( CB_BACKWARDS ) ),
54 : : m_aFindBtn ( this, SfxResId( PB_FIND ) ),
55 : : m_aCancelBtn ( this, SfxResId( PB_CANCELFIND ) ),
56 : : m_sToggleText ( SfxResId( STR_TOGGLE ).toString() ),
57 : : m_sConfigName ( rConfigName ),
58 [ # # ][ # # ]: 0 : m_bIsConstructed ( false )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
59 : :
60 : : {
61 [ # # ]: 0 : FreeResource();
62 : :
63 : : // set handler
64 [ # # ]: 0 : m_aFindBtn.SetClickHdl( LINK( this, SearchDialog, FindHdl ) );
65 [ # # ]: 0 : m_aBackwardsBox.SetClickHdl( LINK( this, SearchDialog, ToggleHdl ) );
66 : : // load config: old search strings and the status of the check boxes
67 [ # # ]: 0 : LoadConfig();
68 : : // we need to change the text of the WrapAround box, depends on the status of the Backwards box
69 [ # # ][ # # ]: 0 : if ( m_aBackwardsBox.IsChecked() )
70 [ # # ]: 0 : ToggleHdl( &m_aBackwardsBox );
71 : : // the search edit should have the focus
72 [ # # ]: 0 : m_aSearchEdit.GrabFocus();
73 : 0 : }
74 : :
75 [ # # ][ # # ]: 0 : SearchDialog::~SearchDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
76 : : {
77 [ # # ]: 0 : SaveConfig();
78 [ # # ]: 0 : m_aCloseHdl.Call( NULL );
79 [ # # ]: 0 : }
80 : :
81 : 0 : void SearchDialog::LoadConfig()
82 : : {
83 [ # # ]: 0 : SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
84 [ # # ][ # # ]: 0 : if ( aViewOpt.Exists() )
85 : : {
86 [ # # ][ # # ]: 0 : m_sWinState = rtl::OUStringToOString(aViewOpt.GetWindowState(), RTL_TEXTENCODING_ASCII_US);
87 [ # # ][ # # ]: 0 : Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
88 : 0 : ::rtl::OUString aTemp;
89 [ # # ]: 0 : if ( aUserItem >>= aTemp )
90 : : {
91 [ # # ]: 0 : String sUserData( aTemp );
92 : : DBG_ASSERT( comphelper::string::getTokenCount(sUserData, ';') == 5, "invalid config data" );
93 : 0 : xub_StrLen nIdx = 0;
94 [ # # ]: 0 : String sSearchText = sUserData.GetToken( 0, ';', nIdx );
95 [ # # ][ # # ]: 0 : m_aWholeWordsBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
[ # # ][ # # ]
96 [ # # ][ # # ]: 0 : m_aMatchCaseBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
[ # # ][ # # ]
97 [ # # ][ # # ]: 0 : m_aWrapAroundBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
[ # # ][ # # ]
98 [ # # ][ # # ]: 0 : m_aBackwardsBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
[ # # ][ # # ]
99 : :
100 : 0 : nIdx = 0;
101 [ # # ]: 0 : while ( nIdx != STRING_NOTFOUND )
102 [ # # ][ # # ]: 0 : m_aSearchEdit.InsertEntry( sSearchText.GetToken( 0, '\t', nIdx ) );
[ # # ]
103 [ # # ][ # # ]: 0 : m_aSearchEdit.SelectEntryPos(0);
[ # # ]
104 : 0 : }
105 : : }
106 : : else
107 [ # # ][ # # ]: 0 : m_aWrapAroundBox.Check( sal_True );
108 : 0 : }
109 : :
110 : 0 : void SearchDialog::SaveConfig()
111 : : {
112 [ # # ]: 0 : SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
113 [ # # ][ # # ]: 0 : aViewOpt.SetWindowState(rtl::OStringToOUString(m_sWinState, RTL_TEXTENCODING_ASCII_US));
114 [ # # ]: 0 : String sUserData;
115 [ # # ]: 0 : sal_uInt16 i = 0, nCount = Min( m_aSearchEdit.GetEntryCount(), MAX_SAVE_COUNT );
116 [ # # ]: 0 : for ( ; i < nCount; ++i )
117 : : {
118 [ # # ][ # # ]: 0 : sUserData += m_aSearchEdit.GetEntry(i);
[ # # ]
119 [ # # ]: 0 : sUserData += '\t';
120 : : }
121 [ # # ][ # # ]: 0 : sUserData = comphelper::string::stripStart(sUserData, '\t');
[ # # ]
122 [ # # ]: 0 : sUserData += ';';
123 [ # # ][ # # ]: 0 : sUserData += String::CreateFromInt32( m_aWholeWordsBox.IsChecked() ? 1 : 0 );
[ # # ][ # # ]
[ # # ]
124 [ # # ]: 0 : sUserData += ';';
125 [ # # ][ # # ]: 0 : sUserData += String::CreateFromInt32( m_aMatchCaseBox.IsChecked() ? 1 : 0 );
[ # # ][ # # ]
[ # # ]
126 [ # # ]: 0 : sUserData += ';';
127 [ # # ][ # # ]: 0 : sUserData += String::CreateFromInt32( m_aWrapAroundBox.IsChecked() ? 1 : 0 );
[ # # ][ # # ]
[ # # ]
128 [ # # ]: 0 : sUserData += ';';
129 [ # # ][ # # ]: 0 : sUserData += String::CreateFromInt32( m_aBackwardsBox.IsChecked() ? 1 : 0 );
[ # # ][ # # ]
[ # # ]
130 : :
131 [ # # ][ # # ]: 0 : Any aUserItem = makeAny( ::rtl::OUString( sUserData ) );
132 [ # # ][ # # ]: 0 : aViewOpt.SetUserItem( USERITEM_NAME, aUserItem );
[ # # ][ # # ]
133 : 0 : }
134 : :
135 : 0 : IMPL_LINK_NOARG(SearchDialog, FindHdl)
136 : : {
137 [ # # ]: 0 : String sSrchTxt = m_aSearchEdit.GetText();
138 [ # # ]: 0 : sal_uInt16 nPos = m_aSearchEdit.GetEntryPos( sSrchTxt );
139 [ # # ][ # # ]: 0 : if ( nPos > 0 && nPos != COMBOBOX_ENTRY_NOTFOUND )
140 [ # # ]: 0 : m_aSearchEdit.RemoveEntry( nPos );
141 [ # # ]: 0 : if ( nPos > 0 )
142 [ # # ]: 0 : m_aSearchEdit.InsertEntry( sSrchTxt, 0 );
143 [ # # ]: 0 : m_aFindHdl.Call( this );
144 [ # # ]: 0 : return 0;
145 : : }
146 : :
147 : 0 : IMPL_LINK_NOARG(SearchDialog, ToggleHdl)
148 : : {
149 [ # # ]: 0 : String sTemp = m_aWrapAroundBox.GetText();
150 [ # # ]: 0 : m_aWrapAroundBox.SetText( m_sToggleText );
151 [ # # ]: 0 : m_sToggleText = sTemp;
152 [ # # ]: 0 : return 0;
153 : : }
154 : :
155 : 0 : void SearchDialog::SetFocusOnEdit()
156 : : {
157 [ # # ][ # # ]: 0 : Selection aSelection( 0, m_aSearchEdit.GetText().Len() );
158 [ # # ]: 0 : m_aSearchEdit.SetSelection( aSelection );
159 [ # # ]: 0 : m_aSearchEdit.GrabFocus();
160 : 0 : }
161 : :
162 : 0 : sal_Bool SearchDialog::Close()
163 : : {
164 : 0 : sal_Bool bRet = ModelessDialog::Close();
165 : 0 : m_aCloseHdl.Call( this );
166 : 0 : return bRet;
167 : : }
168 : :
169 : 0 : void SearchDialog::StateChanged( StateChangedType nStateChange )
170 : : {
171 [ # # ]: 0 : if ( nStateChange == STATE_CHANGE_INITSHOW )
172 : : {
173 [ # # ]: 0 : if (!m_sWinState.isEmpty())
174 : 0 : SetWindowState( m_sWinState );
175 : 0 : m_bIsConstructed = sal_True;
176 : : }
177 : :
178 : 0 : ModelessDialog::StateChanged( nStateChange );
179 : 0 : }
180 : :
181 : 0 : void SearchDialog::Move()
182 : : {
183 : 0 : ModelessDialog::Move();
184 [ # # ][ # # ]: 0 : if ( m_bIsConstructed && IsReallyVisible() )
[ # # ]
185 : 0 : m_sWinState = GetWindowState( WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE );
186 : 0 : }
187 : :
188 : : // ============================================================================
189 : :
190 : : } // namespace sfx2
191 : :
192 : : // ============================================================================
193 : :
194 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|