1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "srchdlg.hxx"
31 #include <comphelper/string.hxx>
32 #include "sfx2/sfxresid.hxx"
33 #include <sfx2/sfxuno.hxx>
35 #include "srchdlg.hrc"
37 #include <tools/debug.hxx>
38 #include <unotools/viewoptions.hxx>
40 using namespace ::com::sun::star::uno
;
42 // ============================================================================
46 #define USERITEM_NAME DEFINE_CONST_OUSTRING("UserItem")
47 #define MAX_SAVE_COUNT (sal_uInt16)10
49 // ============================================================================
51 // ============================================================================
53 SearchDialog::SearchDialog( Window
* pWindow
, const ::rtl::OUString
& rConfigName
) :
55 ModelessDialog( pWindow
, SfxResId( RID_DLG_SEARCH
) ),
57 m_aSearchLabel ( this, SfxResId( FT_SEARCH
) ),
58 m_aSearchEdit ( this, SfxResId( ED_SEARCH
) ),
59 m_aWholeWordsBox ( this, SfxResId( CB_WHOLEWORDS
) ),
60 m_aMatchCaseBox ( this, SfxResId( CB_MATCHCASE
) ),
61 m_aWrapAroundBox ( this, SfxResId( CB_WRAPAROUND
) ),
62 m_aBackwardsBox ( this, SfxResId( CB_BACKWARDS
) ),
63 m_aFindBtn ( this, SfxResId( PB_FIND
) ),
64 m_aCancelBtn ( this, SfxResId( PB_CANCELFIND
) ),
65 m_sToggleText ( SfxResId( STR_TOGGLE
) ),
66 m_sConfigName ( rConfigName
),
67 m_bIsConstructed ( false )
73 m_aFindBtn
.SetClickHdl( LINK( this, SearchDialog
, FindHdl
) );
74 m_aBackwardsBox
.SetClickHdl( LINK( this, SearchDialog
, ToggleHdl
) );
75 // load config: old search strings and the status of the check boxes
77 // we need to change the text of the WrapAround box, depends on the status of the Backwards box
78 if ( m_aBackwardsBox
.IsChecked() )
79 ToggleHdl( &m_aBackwardsBox
);
80 // the search edit should have the focus
81 m_aSearchEdit
.GrabFocus();
84 SearchDialog::~SearchDialog()
87 m_aCloseHdl
.Call( NULL
);
90 void SearchDialog::LoadConfig()
92 SvtViewOptions
aViewOpt( E_DIALOG
, m_sConfigName
);
93 if ( aViewOpt
.Exists() )
95 m_sWinState
= rtl::OUStringToOString(aViewOpt
.GetWindowState(), RTL_TEXTENCODING_ASCII_US
);
96 Any aUserItem
= aViewOpt
.GetUserItem( USERITEM_NAME
);
97 ::rtl::OUString aTemp
;
98 if ( aUserItem
>>= aTemp
)
100 String
sUserData( aTemp
);
101 DBG_ASSERT( comphelper::string::getTokenCount(sUserData
, ';') == 5, "invalid config data" );
103 String sSearchText
= sUserData
.GetToken( 0, ';', nIdx
);
104 m_aWholeWordsBox
.Check( sUserData
.GetToken( 0, ';', nIdx
).ToInt32() == 1 );
105 m_aMatchCaseBox
.Check( sUserData
.GetToken( 0, ';', nIdx
).ToInt32() == 1 );
106 m_aWrapAroundBox
.Check( sUserData
.GetToken( 0, ';', nIdx
).ToInt32() == 1 );
107 m_aBackwardsBox
.Check( sUserData
.GetToken( 0, ';', nIdx
).ToInt32() == 1 );
110 while ( nIdx
!= STRING_NOTFOUND
)
111 m_aSearchEdit
.InsertEntry( sSearchText
.GetToken( 0, '\t', nIdx
) );
112 m_aSearchEdit
.SelectEntryPos(0);
116 m_aWrapAroundBox
.Check( sal_True
);
119 void SearchDialog::SaveConfig()
121 SvtViewOptions
aViewOpt( E_DIALOG
, m_sConfigName
);
122 aViewOpt
.SetWindowState(rtl::OStringToOUString(m_sWinState
, RTL_TEXTENCODING_ASCII_US
));
124 sal_uInt16 i
= 0, nCount
= Min( m_aSearchEdit
.GetEntryCount(), MAX_SAVE_COUNT
);
125 for ( ; i
< nCount
; ++i
)
127 sUserData
+= m_aSearchEdit
.GetEntry(i
);
130 sUserData
.EraseTrailingChars( '\t' );
132 sUserData
+= String::CreateFromInt32( m_aWholeWordsBox
.IsChecked() ? 1 : 0 );
134 sUserData
+= String::CreateFromInt32( m_aMatchCaseBox
.IsChecked() ? 1 : 0 );
136 sUserData
+= String::CreateFromInt32( m_aWrapAroundBox
.IsChecked() ? 1 : 0 );
138 sUserData
+= String::CreateFromInt32( m_aBackwardsBox
.IsChecked() ? 1 : 0 );
140 Any aUserItem
= makeAny( ::rtl::OUString( sUserData
) );
141 aViewOpt
.SetUserItem( USERITEM_NAME
, aUserItem
);
144 IMPL_LINK_NOARG(SearchDialog
, FindHdl
)
146 String sSrchTxt
= m_aSearchEdit
.GetText();
147 sal_uInt16 nPos
= m_aSearchEdit
.GetEntryPos( sSrchTxt
);
148 if ( nPos
> 0 && nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
149 m_aSearchEdit
.RemoveEntry( nPos
);
151 m_aSearchEdit
.InsertEntry( sSrchTxt
, 0 );
152 m_aFindHdl
.Call( this );
156 IMPL_LINK_NOARG(SearchDialog
, ToggleHdl
)
158 String sTemp
= m_aWrapAroundBox
.GetText();
159 m_aWrapAroundBox
.SetText( m_sToggleText
);
160 m_sToggleText
= sTemp
;
164 void SearchDialog::SetFocusOnEdit()
166 Selection
aSelection( 0, m_aSearchEdit
.GetText().Len() );
167 m_aSearchEdit
.SetSelection( aSelection
);
168 m_aSearchEdit
.GrabFocus();
171 sal_Bool
SearchDialog::Close()
173 sal_Bool bRet
= ModelessDialog::Close();
174 m_aCloseHdl
.Call( this );
178 void SearchDialog::StateChanged( StateChangedType nStateChange
)
180 if ( nStateChange
== STATE_CHANGE_INITSHOW
)
182 if (!m_sWinState
.isEmpty())
183 SetWindowState( m_sWinState
);
184 m_bIsConstructed
= sal_True
;
187 ModelessDialog::StateChanged( nStateChange
);
190 void SearchDialog::Move()
192 ModelessDialog::Move();
193 if ( m_bIsConstructed
&& IsReallyVisible() )
194 m_sWinState
= GetWindowState( WINDOWSTATE_MASK_POS
| WINDOWSTATE_MASK_STATE
);
197 // ============================================================================
201 // ============================================================================
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */