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 .
22 #include <com/sun/star/sdbc/XResultSet.hpp>
24 #include <svx/fmsearch.hxx>
25 #include <vcl/weld.hxx>
26 #include <tools/link.hxx>
27 #include <rtl/ustring.hxx>
31 class FmSearchConfigItem
;
34 struct FmSearchProgress
;
38 /// Dialog for searching in Forms/Tables
39 class FmSearchDialog final
: public weld::GenericDialogController
41 friend class FmSearchEngine
;
46 Link
<FmFoundRecordInformation
&, void> m_lnkFoundHandler
; ///< Handler for "found"
47 Link
<FmFoundRecordInformation
&, void>
48 m_lnkCanceledNotFoundHdl
; ///< Handler for Positioning the Cursors
50 Link
<FmSearchContext
&, sal_uInt32
> m_lnkContextSupplier
; ///< for search in contexts
52 /// memorize the currently selected field for every context
53 std::vector
<OUString
> m_arrContextFields
;
55 std::unique_ptr
<FmSearchEngine
> m_pSearchEngine
;
58 std::unique_ptr
<::svxform::FmSearchConfigItem
> m_pConfig
;
61 std::unique_ptr
<weld::RadioButton
> m_prbSearchForText
;
62 std::unique_ptr
<weld::RadioButton
> m_prbSearchForNull
;
63 std::unique_ptr
<weld::RadioButton
> m_prbSearchForNotNull
;
64 std::unique_ptr
<weld::ComboBox
> m_pcmbSearchText
;
65 std::unique_ptr
<weld::Label
> m_pftForm
;
66 std::unique_ptr
<weld::ComboBox
> m_plbForm
;
67 std::unique_ptr
<weld::RadioButton
> m_prbAllFields
;
68 std::unique_ptr
<weld::RadioButton
> m_prbSingleField
;
69 std::unique_ptr
<weld::ComboBox
> m_plbField
;
70 std::unique_ptr
<weld::Label
> m_pftPosition
;
71 std::unique_ptr
<weld::ComboBox
> m_plbPosition
;
72 std::unique_ptr
<weld::CheckButton
> m_pcbUseFormat
;
73 std::unique_ptr
<weld::CheckButton
> m_pcbCase
;
74 std::unique_ptr
<weld::CheckButton
> m_pcbBackwards
;
75 std::unique_ptr
<weld::CheckButton
> m_pcbStartOver
;
76 std::unique_ptr
<weld::CheckButton
> m_pcbWildCard
;
77 std::unique_ptr
<weld::CheckButton
> m_pcbRegular
;
78 std::unique_ptr
<weld::CheckButton
> m_pcbApprox
;
79 std::unique_ptr
<weld::Button
> m_ppbApproxSettings
;
80 std::unique_ptr
<weld::CheckButton
> m_pHalfFullFormsCJK
;
81 std::unique_ptr
<weld::CheckButton
> m_pSoundsLikeCJK
;
82 std::unique_ptr
<weld::Button
> m_pSoundsLikeCJKSettings
;
83 std::unique_ptr
<weld::Label
> m_pftRecord
;
84 std::unique_ptr
<weld::Label
> m_pftHint
;
85 std::unique_ptr
<weld::Button
> m_pbSearchAgain
;
86 std::unique_ptr
<weld::Button
> m_pbClose
;
89 /** This can search in different sets of fields. There is a number of contexts; their names are in strContexts (separated
90 by ';'), the user can choose one of them.
91 When the user chooses a context, lnkContextSupplier is called, it gets a pointer on a FmSearchContext-structure,
92 that has to be filled.
93 The following counts for the search :
94 a) in case of formatted search the iterator itself is used (like in the first constructor)
95 b) in case of formatted search NOT the FormatKey at the fields of the iterator is used, but the respective TextComponent
96 is asked (that's why the original iterator is used; by its move the controls behind the TextComponent-interface are
98 c) in case of not-formatted search a clone of the iterator is used (because the TextComponent-interfaces don't need to
100 (of course needed : the string number i in strUsedFields of a context must correspond with the interface number i in the
101 arrFields of the context)
103 FmSearchDialog(weld::Window
* pParent
, const OUString
& strInitialText
,
104 const std::vector
<OUString
>& _rContexts
, sal_Int16 nInitialContext
,
105 const Link
<FmSearchContext
&, sal_uInt32
>& lnkContextSupplier
);
107 virtual short run() override
;
109 virtual ~FmSearchDialog() override
;
111 /** The found-handler gets in the 'found'-case a pointer on a FmFoundRecordInformation-structure
112 (which is only valid in the handler; so if one needs to memorize the data, don't copy the pointer but
114 This handler MUST be set.
115 Furthermore, it should be considered, that during the handler the search-dialog is still modal.
117 void SetFoundHandler(const Link
<FmFoundRecordInformation
&, void>& lnk
)
119 m_lnkFoundHandler
= lnk
;
122 If the search has been cancelled or has been finished without success, the current data set is always displayed in the
123 search dialog. This handler exists to make this synchronous with the possible display of the caller (it does not
124 necessarily need to be set).
125 The pointer that is passed to the handler points to a FmFoundRecordInformation-structure, for which aPosition and
126 possibly (in a search with contexts) nContext are valid.
128 void SetCanceledNotFoundHdl(const Link
<FmFoundRecordInformation
&, void>& lnk
)
130 m_lnkCanceledNotFoundHdl
= lnk
;
133 inline void SetActiveField(const OUString
& strField
);
136 void Init(std::u16string_view strVisibleFields
, const OUString
& strInitialText
);
137 // only to be used out of the constructors
139 void OnFound(const css::uno::Any
& aCursorPos
, sal_Int16 nFieldPos
);
141 void EnableSearchUI(bool bEnable
);
143 void EnableSearchForDependees(bool bEnable
);
145 void InitContext(sal_Int16 nContext
);
148 void SaveParams() const;
150 // Handler for the Controls
151 DECL_LINK(OnToggledSearchRadio
, weld::Toggleable
&, void);
152 DECL_LINK(OnToggledFieldRadios
, weld::Toggleable
&, void);
153 DECL_LINK(OnClickedSearchAgain
, weld::Button
&, void);
154 DECL_LINK(OnClickedSpecialSettings
, weld::Button
&, void);
156 DECL_LINK(OnSearchTextModified
, weld::ComboBox
&, void);
158 DECL_LINK(OnPositionSelected
, weld::ComboBox
&, void);
159 DECL_LINK(OnFieldSelected
, weld::ComboBox
&, void);
161 DECL_LINK(OnFocusGrabbed
, weld::Widget
&, void);
162 DECL_LINK(OnCheckBoxToggled
, weld::Toggleable
&, void);
164 DECL_LINK(OnContextSelection
, weld::ComboBox
&, void);
166 DECL_LINK(OnSearchProgress
, const FmSearchProgress
*, void);
168 void initCommon(const css::uno::Reference
<css::sdbc::XResultSet
>& _rxCursor
);
171 inline void FmSearchDialog::SetActiveField(const OUString
& strField
)
173 int nInitialField
= m_plbField
->find_text(strField
);
174 if (nInitialField
== -1)
176 m_plbField
->set_active(nInitialField
);
177 OnFieldSelected(*m_plbField
);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */