update dev300-m57
[ooovba.git] / sfx2 / source / dialog / srchdlg.cxx
blob4a97f85a9dec0b274844b5338be6eb5730923850
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: srchdlg.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "srchdlg.hxx"
35 #include "sfxresid.hxx"
36 #include <sfx2/sfxuno.hxx>
38 #include "srchdlg.hrc"
39 #include "dialog.hrc"
40 #include <tools/debug.hxx>
41 #include <svtools/viewoptions.hxx>
43 using namespace ::com::sun::star::uno;
45 // ============================================================================
47 namespace sfx2 {
49 #define USERITEM_NAME DEFINE_CONST_OUSTRING("UserItem")
50 #define MAX_SAVE_COUNT (USHORT)10
52 // ============================================================================
53 // SearchDialog
54 // ============================================================================
56 SearchDialog::SearchDialog( Window* pWindow, const ::rtl::OUString& rConfigName ) :
58 ModelessDialog( pWindow, SfxResId( RID_DLG_SEARCH ) ),
60 m_aSearchLabel ( this, SfxResId( FT_SEARCH ) ),
61 m_aSearchEdit ( this, SfxResId( ED_SEARCH ) ),
62 m_aWholeWordsBox ( this, SfxResId( CB_WHOLEWORDS ) ),
63 m_aMatchCaseBox ( this, SfxResId( CB_MATCHCASE ) ),
64 m_aWrapAroundBox ( this, SfxResId( CB_WRAPAROUND ) ),
65 m_aBackwardsBox ( this, SfxResId( CB_BACKWARDS ) ),
66 m_aFindBtn ( this, SfxResId( PB_FIND ) ),
67 m_aCancelBtn ( this, SfxResId( PB_CANCELFIND ) ),
68 m_sToggleText ( SfxResId( STR_TOGGLE ) ),
69 m_sConfigName ( rConfigName ),
70 m_bIsConstructed ( false )
73 FreeResource();
75 // set handler
76 m_aFindBtn.SetClickHdl( LINK( this, SearchDialog, FindHdl ) );
77 m_aBackwardsBox.SetClickHdl( LINK( this, SearchDialog, ToggleHdl ) );
78 // load config: old search strings and the status of the check boxes
79 LoadConfig();
80 // we need to change the text of the WrapAround box, depends on the status of the Backwards box
81 if ( m_aBackwardsBox.IsChecked() )
82 ToggleHdl( &m_aBackwardsBox );
83 // the search edit should have the focus
84 m_aSearchEdit.GrabFocus();
87 SearchDialog::~SearchDialog()
89 SaveConfig();
90 m_aCloseHdl.Call( NULL );
93 void SearchDialog::LoadConfig()
95 SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
96 if ( aViewOpt.Exists() )
98 m_sWinState = ByteString( aViewOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US );
99 Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
100 ::rtl::OUString aTemp;
101 if ( aUserItem >>= aTemp )
103 String sUserData( aTemp );
104 DBG_ASSERT( sUserData.GetTokenCount() == 5, "invalid config data" );
105 xub_StrLen nIdx = 0;
106 String sSearchText = sUserData.GetToken( 0, ';', nIdx );
107 m_aWholeWordsBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
108 m_aMatchCaseBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
109 m_aWrapAroundBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
110 m_aBackwardsBox.Check( sUserData.GetToken( 0, ';', nIdx ).ToInt32() == 1 );
112 nIdx = 0;
113 while ( nIdx != STRING_NOTFOUND )
114 m_aSearchEdit.InsertEntry( sSearchText.GetToken( 0, '\t', nIdx ) );
115 m_aSearchEdit.SelectEntryPos(0);
118 else
119 m_aWrapAroundBox.Check( TRUE );
122 void SearchDialog::SaveConfig()
124 SvtViewOptions aViewOpt( E_DIALOG, m_sConfigName );
125 aViewOpt.SetWindowState( rtl::OUString::createFromAscii( m_sWinState.GetBuffer() ) );
126 String sUserData;
127 USHORT i = 0, nCount = Min( m_aSearchEdit.GetEntryCount(), MAX_SAVE_COUNT );
128 for ( ; i < nCount; ++i )
130 sUserData += m_aSearchEdit.GetEntry(i);
131 sUserData += '\t';
133 sUserData.EraseTrailingChars( '\t' );
134 sUserData += ';';
135 sUserData += String::CreateFromInt32( m_aWholeWordsBox.IsChecked() ? 1 : 0 );
136 sUserData += ';';
137 sUserData += String::CreateFromInt32( m_aMatchCaseBox.IsChecked() ? 1 : 0 );
138 sUserData += ';';
139 sUserData += String::CreateFromInt32( m_aWrapAroundBox.IsChecked() ? 1 : 0 );
140 sUserData += ';';
141 sUserData += String::CreateFromInt32( m_aBackwardsBox.IsChecked() ? 1 : 0 );
143 Any aUserItem = makeAny( ::rtl::OUString( sUserData ) );
144 aViewOpt.SetUserItem( USERITEM_NAME, aUserItem );
147 IMPL_LINK( SearchDialog, FindHdl, PushButton*, EMPTYARG )
149 String sSrchTxt = m_aSearchEdit.GetText();
150 USHORT nPos = m_aSearchEdit.GetEntryPos( sSrchTxt );
151 if ( nPos > 0 && nPos != COMBOBOX_ENTRY_NOTFOUND )
152 m_aSearchEdit.RemoveEntry( nPos );
153 if ( nPos > 0 )
154 m_aSearchEdit.InsertEntry( sSrchTxt, 0 );
155 m_aFindHdl.Call( this );
156 return 0;
159 IMPL_LINK( SearchDialog, ToggleHdl, CheckBox*, EMPTYARG )
161 String sTemp = m_aWrapAroundBox.GetText();
162 m_aWrapAroundBox.SetText( m_sToggleText );
163 m_sToggleText = sTemp;
164 return 0;
167 void SearchDialog::SetFocusOnEdit()
169 Selection aSelection( 0, m_aSearchEdit.GetText().Len() );
170 m_aSearchEdit.SetSelection( aSelection );
171 m_aSearchEdit.GrabFocus();
174 BOOL SearchDialog::Close()
176 BOOL bRet = ModelessDialog::Close();
177 m_aCloseHdl.Call( this );
178 return bRet;
181 void SearchDialog::StateChanged( StateChangedType nStateChange )
183 if ( nStateChange == STATE_CHANGE_INITSHOW )
185 if ( m_sWinState.Len() )
186 SetWindowState( m_sWinState );
187 m_bIsConstructed = TRUE;
190 ModelessDialog::StateChanged( nStateChange );
193 void SearchDialog::Move()
195 ModelessDialog::Move();
196 if ( m_bIsConstructed && IsReallyVisible() )
197 m_sWinState = GetWindowState( WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE );
200 // ============================================================================
202 } // namespace sfx2
204 // ============================================================================