LibreOffice Module sw (master)  1
inputwin.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_INPUTWIN_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_INPUTWIN_HXX
21 
22 #include <sal/config.h>
23 
24 #include <string_view>
25 
27 #include <vcl/toolbox.hxx>
28 
29 #include <sfx2/childwin.hxx>
30 
31 class SwFieldMgr;
32 class SwWrtShell;
33 class SwView;
34 class SfxDispatcher;
35 
36 class InputEdit final : public InterimItemWindow
37 {
38 private:
39  std::unique_ptr<weld::Entry> m_xWidget;
40 
41  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
42  DECL_LINK(ActivateHdl, weld::Entry&, bool);
43 public:
45  : InterimItemWindow(pParent, "modules/swriter/ui/inputeditbox.ui", "InputEditBox")
46  , m_xWidget(m_xBuilder->weld_entry("entry"))
47  {
48  InitControlBase(m_xWidget.get());
49 
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());
53  }
54 
55  void UpdateRange(std::u16string_view rSel, const OUString& rTableName);
56 
57  virtual void dispose() override
58  {
59  m_xWidget.reset();
61  }
62 
63  void set_text(const OUString& rText)
64  {
65  m_xWidget->set_text(rText);
66  }
67 
68  OUString get_text() const
69  {
70  return m_xWidget->get_text();
71  }
72 
73  void set_accessible_name(const OUString& rName)
74  {
75  m_xWidget->set_accessible_name(rName);
76  }
77 
78  void replace_selection(const OUString& rText)
79  {
80  int nStartPos, nEndPos;
81  m_xWidget->get_selection_bounds(nStartPos, nEndPos);
82  if (nStartPos > nEndPos)
83  std::swap(nStartPos, nEndPos);
84 
85  m_xWidget->replace_selection(rText);
86 
87  nStartPos = nStartPos + rText.getLength();
88  m_xWidget->select_region(nStartPos, nStartPos);
89  }
90 
91  void select_region(int nStartPos, int nEndPos)
92  {
93  m_xWidget->select_region(nStartPos, nEndPos);
94  }
95 
97  {
98  m_xWidget->connect_changed(rLink);
99  }
100 
101  virtual ~InputEdit() override
102  {
103  disposeOnce();
104  }
105 };
106 
107 
108 class PosEdit final : public InterimItemWindow
109 {
110 private:
111  std::unique_ptr<weld::Entry> m_xWidget;
112 
113  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
114 public:
116  : InterimItemWindow(pParent, "modules/swriter/ui/poseditbox.ui", "PosEditBox")
117  , m_xWidget(m_xBuilder->weld_entry("entry"))
118  {
119  InitControlBase(m_xWidget.get());
120 
121  m_xWidget->connect_key_press(LINK(this, PosEdit, KeyInputHdl));
122  SetSizePixel(m_xWidget->get_preferred_size());
123  }
124 
125  virtual void dispose() override
126  {
127  m_xWidget.reset();
129  }
130 
131  void set_text(const OUString& rText)
132  {
133  m_xWidget->set_text(rText);
134  }
135 
136  void set_accessible_name(const OUString& rName)
137  {
138  m_xWidget->set_accessible_name(rName);
139  }
140 
141  virtual ~PosEdit() override
142  {
143  disposeOnce();
144  }
145 };
146 
147 class SwInputWindow final : public ToolBox
148 {
149 friend class InputEdit;
150 
153  std::unique_ptr<SwFieldMgr> pMgr;
157 
158  bool bFirst : 1; // initialisations at first call
159  bool bIsTable : 1;
160  bool bDelSel : 1;
161  bool m_bDoesUndo : 1;
162  bool m_bResetUndo : 1;
163  bool m_bCallUndo : 1;
164 
166 
167  void DelBoxContent();
168  DECL_LINK(ModifyHdl, weld::Entry&, void);
169 
170  using Window::IsActive;
171 
172  virtual void Resize() override;
173  virtual void Click() override;
174  void MenuHdl(std::string_view command);
175  DECL_LINK( DropdownClickHdl, ToolBox*, void );
176  void ApplyFormula();
177  void CancelFormula();
178 
179 public:
180  SwInputWindow(vcl::Window* pParent, SfxDispatcher const * pDispatcher);
181  virtual ~SwInputWindow() override;
182  virtual void dispose() override;
183 
184  void ShowWin();
185 
186  DECL_LINK( SelTableCellsNotify, SwWrtShell&, void );
187 
188  void SetFormula( const OUString& rFormula );
189  const SwView* GetView() const{return pView;}
190 };
191 
193 {
195 public:
197  sal_uInt16 nId,
198  SfxBindings const *,
199  SfxChildWinInfo* );
200  virtual ~SwInputChild() override;
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();}
206 
207 };
208 
209 #endif
210 
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void replace_selection(const OUString &rText)
Definition: inputwin.hxx:78
virtual void Resize() override
Definition: inputwin.cxx:174
bool m_bCallUndo
Definition: inputwin.hxx:163
virtual void dispose() override
Definition: inputwin.cxx:138
SwWrtShell * pWrtShell
Definition: inputwin.hxx:154
virtual ~InputEdit() override
Definition: inputwin.hxx:101
void ApplyFormula()
Definition: inputwin.cxx:331
void DelBoxContent()
Definition: inputwin.cxx:463
SwView * pView
Definition: inputwin.hxx:155
SwInputWindow(vcl::Window *pParent, SfxDispatcher const *pDispatcher)
Definition: inputwin.cxx:67
virtual void SetSizePixel(const Size &rNewSize)
void CancelFormula()
Definition: inputwin.cxx:364
std::unique_ptr< weld::Entry > m_xWidget
Definition: inputwin.hxx:39
vcl::Window * GetWindow() const
VclPtr< PosEdit > mxPos
Definition: inputwin.hxx:151
virtual void Click() override
Definition: inputwin.cxx:312
virtual void dispose() override
Definition: inputwin.hxx:125
Used by the UI to modify the document model.
Definition: wrtsh.hxx:91
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
PosEdit(vcl::Window *pParent)
Definition: inputwin.hxx:115
void MenuHdl(std::string_view command)
Definition: inputwin.cxx:292
void CleanupUglyHackWithUndo()
Definition: inputwin.cxx:157
SFX_DECL_CHILDWINDOW_WITHID(SwInputChild)
void set_text(const OUString &rText)
Definition: inputwin.hxx:131
SwInputChild(vcl::Window *, sal_uInt16 nId, SfxBindings const *, SfxChildWinInfo *)
Definition: inputwin.cxx:596
void SetFormula(const OUString &rFormula)
Definition: inputwin.hxx:202
InputEdit(vcl::Window *pParent)
Definition: inputwin.hxx:44
virtual ~SwInputChild() override
Definition: inputwin.cxx:608
void set_text(const OUString &rText)
Definition: inputwin.hxx:63
OUString aCurrentTableName
Definition: inputwin.hxx:156
void set_accessible_name(const OUString &rName)
Definition: inputwin.hxx:73
void ShowWin()
Definition: inputwin.cxx:186
std::unique_ptr< SwFieldMgr > pMgr
Definition: inputwin.hxx:153
SfxDispatcher * pDispatch
Definition: inputwin.hxx:194
virtual ~SwInputWindow() override
Definition: inputwin.cxx:133
OUString sOldFormula
Definition: inputwin.hxx:156
void connect_changed(const Link< weld::Entry &, void > &rLink)
Definition: inputwin.hxx:96
virtual ~PosEdit() override
Definition: inputwin.hxx:141
virtual void dispose() override
Definition: inputwin.hxx:57
DECL_LINK(ModifyHdl, weld::Entry &, void)
virtual void dispose() override
bool m_bDoesUndo
Definition: inputwin.hxx:161
void UpdateRange(std::u16string_view rSel, const OUString &rTableName)
Definition: inputwin.cxx:501
std::unique_ptr< weld::Entry > m_xWidget
Definition: inputwin.hxx:111
void select_region(int nStartPos, int nEndPos)
Definition: inputwin.hxx:91
std::unique_ptr< weld::Builder > m_xBuilder
const SwView * GetView() const
Definition: inputwin.hxx:189
OUString get_text() const
Definition: inputwin.hxx:68
const SwView * GetView() const
Definition: inputwin.hxx:204
void set_accessible_name(const OUString &rName)
Definition: inputwin.hxx:136
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
Definition: view.hxx:144
void InitControlBase(weld::Widget *pWidget)
bool m_bResetUndo
Definition: inputwin.hxx:162
VclPtr< InputEdit > mxEdit
Definition: inputwin.hxx:152
void SetFormula(const OUString &rFormula)
Definition: inputwin.cxx:434