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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_INPUTWIN_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_INPUTWIN_HXX
22 #include <vcl/InterimItemWindow.hxx>
23 #include <vcl/menu.hxx>
24 #include <vcl/toolbox.hxx>
26 #include <sfx2/childwin.hxx>
33 class InputEdit final
: public InterimItemWindow
36 std::unique_ptr
<weld::Entry
> m_xWidget
;
38 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
39 DECL_LINK(ActivateHdl
, weld::Entry
&, bool);
41 InputEdit(vcl::Window
* pParent
)
42 : InterimItemWindow(pParent
, "modules/swriter/ui/inputeditbox.ui", "InputEditBox")
43 , m_xWidget(m_xBuilder
->weld_entry("entry"))
45 InitControlBase(m_xWidget
.get());
47 m_xWidget
->connect_key_press(LINK(this, InputEdit
, KeyInputHdl
));
48 m_xWidget
->connect_activate(LINK(this, InputEdit
, ActivateHdl
));
49 SetSizePixel(m_xWidget
->get_preferred_size());
52 void UpdateRange(const OUString
& rSel
, const OUString
& rTableName
);
54 virtual void dispose() override
57 InterimItemWindow::dispose();
60 void set_text(const OUString
& rText
)
62 m_xWidget
->set_text(rText
);
65 OUString
get_text() const
67 return m_xWidget
->get_text();
70 void set_accessible_name(const OUString
& rName
)
72 m_xWidget
->set_accessible_name(rName
);
75 void replace_selection(const OUString
& rText
)
77 int nStartPos
, nEndPos
;
78 m_xWidget
->get_selection_bounds(nStartPos
, nEndPos
);
79 if (nStartPos
> nEndPos
)
80 std::swap(nStartPos
, nEndPos
);
82 m_xWidget
->replace_selection(rText
);
84 nStartPos
= nStartPos
+ rText
.getLength();
85 m_xWidget
->select_region(nStartPos
, nStartPos
);
88 void select_region(int nStartPos
, int nEndPos
)
90 m_xWidget
->select_region(nStartPos
, nEndPos
);
93 void connect_changed(const Link
<weld::Entry
&, void>& rLink
)
95 m_xWidget
->connect_changed(rLink
);
98 virtual ~InputEdit() override
105 class PosEdit final
: public InterimItemWindow
108 std::unique_ptr
<weld::Entry
> m_xWidget
;
110 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
112 PosEdit(vcl::Window
* pParent
)
113 : InterimItemWindow(pParent
, "modules/swriter/ui/poseditbox.ui", "PosEditBox")
114 , m_xWidget(m_xBuilder
->weld_entry("entry"))
116 InitControlBase(m_xWidget
.get());
118 m_xWidget
->connect_key_press(LINK(this, PosEdit
, KeyInputHdl
));
119 SetSizePixel(m_xWidget
->get_preferred_size());
122 virtual void dispose() override
125 InterimItemWindow::dispose();
128 void set_text(const OUString
& rText
)
130 m_xWidget
->set_text(rText
);
133 void set_accessible_name(const OUString
& rName
)
135 m_xWidget
->set_accessible_name(rName
);
138 virtual ~PosEdit() override
144 class SwInputWindow final
: public ToolBox
146 friend class InputEdit
;
148 VclPtr
<PosEdit
> mxPos
;
149 VclPtr
<InputEdit
> mxEdit
;
150 std::unique_ptr
<SwFieldMgr
> pMgr
;
151 SwWrtShell
* pWrtShell
;
153 OUString aCurrentTableName
, sOldFormula
;
155 bool bFirst
: 1; // initialisations at first call
158 bool m_bDoesUndo
: 1;
159 bool m_bResetUndo
: 1;
160 bool m_bCallUndo
: 1;
162 void CleanupUglyHackWithUndo();
164 void DelBoxContent();
165 DECL_LINK(ModifyHdl
, weld::Entry
&, void);
167 using Window::IsActive
;
169 virtual void Resize() override
;
170 virtual void Click() override
;
171 DECL_LINK( MenuHdl
, Menu
*, bool );
172 DECL_LINK( DropdownClickHdl
, ToolBox
*, void );
174 void CancelFormula();
177 SwInputWindow(vcl::Window
* pParent
, SfxDispatcher
const * pDispatcher
);
178 virtual ~SwInputWindow() override
;
179 virtual void dispose() override
;
183 DECL_LINK( SelTableCellsNotify
, SwWrtShell
&, void );
185 void SetFormula( const OUString
& rFormula
);
186 const SwView
* GetView() const{return pView
;}
189 class SwInputChild
: public SfxChildWindow
191 SfxDispatcher
* pDispatch
;
193 SwInputChild( vcl::Window
* ,
197 virtual ~SwInputChild() override
;
198 SFX_DECL_CHILDWINDOW_WITHID( SwInputChild
);
199 void SetFormula( const OUString
& rFormula
)
200 { static_cast<SwInputWindow
*>(GetWindow())->SetFormula( rFormula
); }
201 const SwView
* GetView() const
202 { return static_cast<SwInputWindow
*>(GetWindow())->GetView();}
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */