Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / inc / inputwin.hxx
blob05d181a886237bffc1ca17e4111e7e43eb229377
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_INPUTWIN_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_INPUTWIN_HXX
22 #include <sal/config.h>
24 #include <string_view>
26 #include <vcl/InterimItemWindow.hxx>
27 #include <vcl/toolbox.hxx>
29 #include <sfx2/childwin.hxx>
31 class SwFieldMgr;
32 class SwWrtShell;
33 class SwView;
34 class SfxDispatcher;
36 class InputEdit final : public InterimItemWindow
38 private:
39 std::unique_ptr<weld::Entry> m_xWidget;
41 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
42 DECL_LINK(ActivateHdl, weld::Entry&, bool);
43 public:
44 InputEdit(vcl::Window* pParent)
45 : InterimItemWindow(pParent, "modules/swriter/ui/inputeditbox.ui", "InputEditBox")
46 , m_xWidget(m_xBuilder->weld_entry("entry"))
48 InitControlBase(m_xWidget.get());
50 m_xWidget->connect_key_press(LINK(this, InputEdit, KeyInputHdl));
51 m_xWidget->connect_activate(LINK(this, InputEdit, ActivateHdl));
52 SetSizePixel(m_xWidget->get_preferred_size());
55 void UpdateRange(std::u16string_view rSel, const OUString& rTableName);
57 virtual void dispose() override
59 m_xWidget.reset();
60 InterimItemWindow::dispose();
63 void set_text(const OUString& rText)
65 m_xWidget->set_text(rText);
68 OUString get_text() const
70 return m_xWidget->get_text();
73 void set_accessible_name(const OUString& rName)
75 m_xWidget->set_accessible_name(rName);
78 void replace_selection(const OUString& rText)
80 int nStartPos, nEndPos;
81 m_xWidget->get_selection_bounds(nStartPos, nEndPos);
82 if (nStartPos > nEndPos)
83 std::swap(nStartPos, nEndPos);
85 m_xWidget->replace_selection(rText);
87 nStartPos = nStartPos + rText.getLength();
88 m_xWidget->select_region(nStartPos, nStartPos);
91 void select_region(int nStartPos, int nEndPos)
93 m_xWidget->select_region(nStartPos, nEndPos);
96 void connect_changed(const Link<weld::Entry&, void>& rLink)
98 m_xWidget->connect_changed(rLink);
101 virtual ~InputEdit() override
103 disposeOnce();
108 class PosEdit final : public InterimItemWindow
110 private:
111 std::unique_ptr<weld::Entry> m_xWidget;
113 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
114 public:
115 PosEdit(vcl::Window* pParent)
116 : InterimItemWindow(pParent, "modules/swriter/ui/poseditbox.ui", "PosEditBox")
117 , m_xWidget(m_xBuilder->weld_entry("entry"))
119 InitControlBase(m_xWidget.get());
121 m_xWidget->connect_key_press(LINK(this, PosEdit, KeyInputHdl));
122 SetSizePixel(m_xWidget->get_preferred_size());
125 virtual void dispose() override
127 m_xWidget.reset();
128 InterimItemWindow::dispose();
131 void set_text(const OUString& rText)
133 m_xWidget->set_text(rText);
136 void set_accessible_name(const OUString& rName)
138 m_xWidget->set_accessible_name(rName);
141 virtual ~PosEdit() override
143 disposeOnce();
147 class SwInputWindow final : public ToolBox
149 friend class InputEdit;
151 VclPtr<PosEdit> mxPos;
152 VclPtr<InputEdit> mxEdit;
153 std::unique_ptr<SwFieldMgr> m_pMgr;
154 SwWrtShell* m_pWrtShell;
155 SwView* m_pView;
156 OUString m_aCurrentTableName, m_sOldFormula;
158 bool m_bFirst : 1; // initialisations at first call
159 bool m_bIsTable : 1;
160 bool m_bDelSel : 1;
161 bool m_bDoesUndo : 1;
162 bool m_bResetUndo : 1;
163 bool m_bCallUndo : 1;
165 void CleanupUglyHackWithUndo();
167 void DelBoxContent();
168 DECL_LINK(ModifyHdl, weld::Entry&, void);
170 using Window::IsActive;
172 virtual void Resize() override;
173 virtual void Click() override;
174 void MenuHdl(std::u16string_view command);
175 DECL_LINK( DropdownClickHdl, ToolBox*, void );
176 void ApplyFormula();
177 void CancelFormula();
179 public:
180 SwInputWindow(vcl::Window* pParent, SfxDispatcher const * pDispatcher);
181 virtual ~SwInputWindow() override;
182 virtual void dispose() override;
184 void ShowWin();
186 DECL_LINK( SelTableCellsNotify, SwWrtShell&, void );
188 void SetFormula( const OUString& rFormula );
189 const SwView* GetView() const{return m_pView;}
192 class SwInputChild final : public SfxChildWindow
194 SfxDispatcher* m_pDispatch;
195 public:
196 SwInputChild( vcl::Window* ,
197 sal_uInt16 nId,
198 SfxBindings const *,
199 SfxChildWinInfo* );
200 virtual ~SwInputChild() override;
201 SFX_DECL_CHILDWINDOW_WITHID( SwInputChild );
202 void SetFormula( const OUString& rFormula )
203 { static_cast<SwInputWindow*>(GetWindow())->SetFormula( rFormula ); }
204 const SwView* GetView() const
205 { return static_cast<SwInputWindow*>(GetWindow())->GetView();}
209 #endif
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */