LibreOffice Module vcl (master)  1
edit.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 
20 #ifndef INCLUDED_VCL_EDIT_HXX
21 #define INCLUDED_VCL_EDIT_HXX
22 
23 #include <vcl/ctrl.hxx>
24 #include <vcl/textfilter.hxx>
25 
26 #include <memory>
27 
28 #include <o3tl/deleter.hxx>
29 #include <tools/solar.h>
30 #include <vcl/dllapi.h>
31 #include <vcl/menu.hxx>
32 #include <vcl/dndhelp.hxx>
33 #include <vcl/vclptr.hxx>
34 #include <com/sun/star/uno/Reference.h>
35 
36 namespace com {
37 namespace sun {
38 namespace star {
39 namespace i18n {
40  class XBreakIterator;
41  class XExtendedInputSequenceChecker;
42 }}}}
43 namespace weld {
44  class Widget;
45 }
46 
47 class VclBuilder;
48 struct DDInfo;
49 struct Impl_IMEInfos;
50 
51 #define EDIT_NOLIMIT SAL_MAX_INT32
52 #define EDIT_UPDATEDATA_TIMEOUT 350
53 
54 typedef OUString (*FncGetSpecialChars)( weld::Widget* pWin, const vcl::Font& rFont );
55 
56 class Timer;
57 
59 {
60 private:
62  std::unique_ptr<Timer> mpUpdateDataTimer;
64  std::unique_ptr<DDInfo, o3tl::default_delete<DDInfo>> mpDDInfo;
65  std::unique_ptr<Impl_IMEInfos> mpIMEInfos;
66  OUStringBuffer maText;
68  OUString maSaveValue;
69  OUString maUndoText;
70  long mnXOffset;
72  sal_uInt16 mnAlign;
73  sal_Int32 mnMaxTextLen;
74  sal_Int32 mnWidthInChars;
75  sal_Int32 mnMaxWidthChars;
77  bool mbModified:1,
78  mbSelectAllSingleClick:1,
79  mbInternModified:1,
80  mbReadOnly:1,
81  mbInsertMode:1,
82  mbClickedInSelection:1,
83  mbIsSubEdit:1,
84  mbActivePopup:1,
85  mbForceControlBackground:1,
86  mbPassword;
91  std::unique_ptr<VclBuilder> mpUIBuilder;
92 
93  css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC;
94 
95  DECL_DLLPRIVATE_LINK(ImplUpdateDataHdl, Timer*, void);
96 
97  SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const;
98  SAL_DLLPRIVATE void ImplInitEditData();
99  SAL_DLLPRIVATE void ImplModified();
100  SAL_DLLPRIVATE OUString ImplGetText() const;
101  SAL_DLLPRIVATE void ImplRepaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle);
102  SAL_DLLPRIVATE void ImplInvalidateOrRepaint();
103  SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
104  SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection );
105  SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = nullptr, bool bIsUserInput = false );
106  SAL_DLLPRIVATE static OUString ImplGetValidString( const OUString& rString );
107  SAL_DLLPRIVATE void ImplClearBackground(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle, long nXStart, long nXEnd);
108  SAL_DLLPRIVATE void ImplPaintBorder(vcl::RenderContext const & rRenderContext);
109  SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true );
110  SAL_DLLPRIVATE void ImplAlign();
111  SAL_DLLPRIVATE void ImplAlignAndPaint();
112  SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const;
113  SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect );
114  SAL_DLLPRIVATE void ImplShowDDCursor();
115  SAL_DLLPRIVATE void ImplHideDDCursor();
116  SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
117  SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
118  SAL_DLLPRIVATE void ImplCopy(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard);
119  SAL_DLLPRIVATE void ImplPaste(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard);
120  SAL_DLLPRIVATE long ImplGetTextYPosition() const;
121  SAL_DLLPRIVATE css::uno::Reference<css::i18n::XExtendedInputSequenceChecker > const & ImplGetInputSequenceChecker();
122  SAL_DLLPRIVATE static css::uno::Reference<css::i18n::XBreakIterator > ImplGetBreakIterator();
123  SAL_DLLPRIVATE void filterText();
124 
125 protected:
127  using Window::ImplInit;
128  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
129  SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
130  SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true );
131  SAL_DLLPRIVATE ControlType ImplGetNativeControlType() const;
132  SAL_DLLPRIVATE long ImplGetExtraXOffset() const;
133  SAL_DLLPRIVATE long ImplGetExtraYOffset() const;
134  static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( vcl::Window* pWin );
135 
136  css::uno::Reference<css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
137 
138  // DragAndDropClient
142  virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override;
143  virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent& dsde) override;
144  virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override;
145  virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee) override;
146  virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) override;
147  virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override;
148 
149 protected:
150  Edit(WindowType nType);
151  virtual void FillLayoutData() const override;
152  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
153 public:
154  // public because needed in button.cxx
155  SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext const & rRenderContext, WinBits nStyle);
156 
157  Edit( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
158  virtual ~Edit() override;
159  virtual void dispose() override;
160 
161  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
162  virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
163  virtual void KeyInput( const KeyEvent& rKEvt ) override;
164  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
165  virtual void Resize() override;
166  virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
167  virtual void GetFocus() override;
168  virtual void LoseFocus() override;
169  virtual void Tracking( const TrackingEvent& rTEvt ) override;
170  virtual void Command( const CommandEvent& rCEvt ) override;
171  virtual void StateChanged( StateChangedType nType ) override;
172  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
173 
174  virtual void Modify();
175  virtual void UpdateData();
176 
177  static bool IsCharInput( const KeyEvent& rKEvt );
178 
179  virtual void SetModifyFlag();
180  virtual void ClearModifyFlag();
181  virtual bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
182 
183  virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
184  virtual void DisableUpdateData();
185 
186  void SetEchoChar( sal_Unicode c );
187  sal_Unicode GetEchoChar() const { return mcEchoChar; }
188 
189  virtual void SetReadOnly( bool bReadOnly = true );
190  virtual bool IsReadOnly() const { return mbReadOnly; }
191 
192  void SetSelectAllSingleClick( bool bSelectAllSingleClick );
193  bool IsSelectAllSingleClick() const { return mbSelectAllSingleClick; }
194 
195  void SetInsertMode( bool bInsert );
196  bool IsInsertMode() const;
197 
198  virtual void SetMaxTextLen( sal_Int32 nMaxLen );
199  virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
200 
201  void SetWidthInChars(sal_Int32 nWidthInChars);
202  sal_Int32 GetWidthInChars() const { return mnWidthInChars; }
203 
204  void setMaxWidthChars(sal_Int32 nWidth);
205 
206  virtual void SetSelection( const Selection& rSelection );
207  virtual const Selection& GetSelection() const;
208 
209  virtual void ReplaceSelected( const OUString& rStr );
210  virtual void DeleteSelected();
211  virtual OUString GetSelected() const;
212 
213  virtual void Cut();
214  virtual void Copy();
215  virtual void Paste();
216  void Undo();
217 
218  virtual void SetText( const OUString& rStr ) override;
219  virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
220  virtual OUString GetText() const override;
221 
222  void SetCursorAtLast();
223 
224  void SetPlaceholderText( const OUString& rStr );
225  OUString GetPlaceholderText() const;
226 
227  void SaveValue() { maSaveValue = GetText(); }
228  const OUString& GetSavedValue() const { return maSaveValue; }
229  bool IsValueChangedFromSaved() const { return maSaveValue != GetText(); }
230 
231  virtual void SetModifyHdl( const Link<Edit&,void>& rLink ) { maModifyHdl = rLink; }
232  virtual const Link<Edit&,void>& GetModifyHdl() const { return maModifyHdl; }
233  virtual void SetUpdateDataHdl( const Link<Edit&,void>& rLink ) { maUpdateDataHdl = rLink; }
234 
235  void SetActivateHdl(const Link<Edit&,bool>& rLink) { maActivateHdl = rLink; }
236 
237  void SetSubEdit( Edit* pEdit );
238  Edit* GetSubEdit() const { return mpSubEdit; }
239 
240  void SetAutocompleteHdl( const Link<Edit&,void>& rLink ) { maAutocompleteHdl = rLink; }
241  const Link<Edit&,void>& GetAutocompleteHdl() const { return maAutocompleteHdl; }
242 
243  virtual Size CalcMinimumSize() const;
244  virtual Size CalcMinimumSizeForText(const OUString &rString) const;
245  virtual Size GetOptimalSize() const override;
246  virtual Size CalcSize(sal_Int32 nChars) const;
247  sal_Int32 GetMaxVisChars() const;
248 
249  sal_Int32 GetCharPos( const Point& rWindowPos ) const;
250 
251  // shows a warning box saying "text too long, truncated"
252  static void ShowTruncationWarning(weld::Widget* pParent);
253 
254  static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
255  static FncGetSpecialChars GetGetSpecialCharsFunction();
256 
257  VclPtr<PopupMenu> CreatePopupMenu();
258 
259  virtual OUString GetSurroundingText() const override;
260  virtual Selection GetSurroundingTextSelection() const override;
261  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
262 
263  void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; }
264 
265  virtual FactoryFunction GetUITestFactory() const override;
266 
267  // returns the minimum size a bordered Edit should have given the current
268  // global style settings (needed by sc's inputwin.cxx)
269  static Size GetMinimumEditSize();
270 
271  void SetForceControlBackground(bool b) { mbForceControlBackground = b; }
272 
273  bool IsPassword() const { return mbPassword; }
274 };
275 
276 #endif // INCLUDED_VCL_EDIT_HXX
277 
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetActivateHdl(const Link< Edit &, bool > &rLink)
Definition: edit.hxx:235
#define EDIT_UPDATEDATA_TIMEOUT
Definition: edit.hxx:52
sal_Int32 mnMaxWidthChars
Definition: edit.hxx:75
OUString maSaveValue
Definition: edit.hxx:68
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3766
sal_Int32 GetWidthInChars() const
Definition: edit.hxx:202
void GetSelection(struct ESelection &rSel, SvxTextForwarder const *pForwarder)
Link< Edit &, void > maModifyHdl
Definition: edit.hxx:87
DECL_DLLPRIVATE_LINK(ImplHandlePaintHdl, Timer *, void)
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:412
sal_Unicode GetEchoChar() const
Definition: edit.hxx:187
Edit * GetSubEdit() const
Definition: edit.hxx:238
long mnXOffset
Definition: edit.hxx:70
virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent &dte)
Definition: dndhelp.cxx:44
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
OUString(* FncGetSpecialChars)(weld::Widget *pWin, const vcl::Font &rFont)
Definition: edit.hxx:54
void SaveValue()
Definition: edit.hxx:227
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
OUString maPlaceholderText
Definition: edit.hxx:67
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
void SetForceControlBackground(bool b)
Definition: edit.hxx:271
sal_uInt16 mnAlign
Definition: edit.hxx:72
css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mxDnDListener
Definition: edit.hxx:136
virtual const Link< Edit &, void > & GetModifyHdl() const
Definition: edit.hxx:232
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: ctrl.cxx:418
virtual bool IsModified() const
Definition: edit.hxx:181
virtual void MouseButtonUp(const MouseEvent &rMEvt)
Definition: mouse.cxx:419
StateChangedType
Definition: window.hxx:309
virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent &dtde)
Definition: dndhelp.cxx:48
sal_Int64 WinBits
sal_uInt16 sal_Unicode
virtual void SetModifyHdl(const Link< Edit &, void > &rLink)
Definition: edit.hxx:231
Link< Edit &, void > maUpdateDataHdl
Definition: edit.hxx:88
virtual void Tracking(const TrackingEvent &rTEvt)
Definition: window.cxx:1895
virtual sal_Int32 GetMaxTextLen() const
Definition: edit.hxx:199
std::unique_ptr< Timer > mpUpdateDataTimer
Definition: edit.hxx:62
const Link< Edit &, void > & GetAutocompleteHdl() const
Definition: edit.hxx:241
virtual OUString GetText() const
Definition: window.cxx:3051
sal_Int32 mnMaxTextLen
Definition: edit.hxx:73
Definition: edit.cxx:86
Definition: edit.hxx:58
OUString maUndoText
Definition: edit.hxx:69
virtual Selection GetSurroundingTextSelection() const
Definition: window.cxx:3660
std::unique_ptr< Impl_IMEInfos > mpIMEInfos
Definition: edit.hxx:65
virtual void Draw(::OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags)
Definition: window.cxx:1792
OUStringBuffer maText
Definition: edit.hxx:66
virtual void SetUpdateDataHdl(const Link< Edit &, void > &rLink)
Definition: edit.hxx:233
Selection maSelection
Definition: edit.hxx:71
virtual OUString GetSurroundingText() const
Definition: window.cxx:3655
DrawFlags
Definition: window.hxx:352
virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent &dsde)
Definition: dndhelp.cxx:32
virtual void SetText(const OUString &rStr) override
Definition: ctrl.cxx:95
bool mbModified
Definition: edit.hxx:77
std::unique_ptr< VclBuilder > mpUIBuilder
Definition: edit.hxx:91
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
sal_Unicode mcEchoChar
Definition: edit.hxx:76
void SetTextFilter(TextFilter *pFilter)
Definition: edit.hxx:263
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
virtual bool set_property(const OString &rKey, const OUString &rValue)
Definition: window2.cxx:1425
virtual void LoseFocus()
Definition: window.cxx:1818
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1767
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:930
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
std::unique_ptr< DDInfo, o3tl::default_delete< DDInfo > > mpDDInfo
Definition: edit.hxx:64
css::uno::Reference< css::i18n::XExtendedInputSequenceChecker > mxISC
Definition: edit.hxx:93
Link< Edit &, void > maAutocompleteHdl
Definition: edit.hxx:89
virtual void Resize() override
Definition: ctrl.cxx:74
WindowType
Definition: ctrl.hxx:33
virtual void GetFocus()
Definition: window.cxx:1804
unsigned char sal_uInt8
Link< Edit &, bool > maActivateHdl
Definition: edit.hxx:90
const OUString & GetSavedValue() const
Definition: edit.hxx:228
bool IsSelectAllSingleClick() const
Definition: edit.hxx:193
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1010
virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent &dge)
Definition: dndhelp.cxx:28
VclPtr< Edit > mpSubEdit
Definition: edit.hxx:61
void SetAutocompleteHdl(const Link< Edit &, void > &rLink)
Definition: edit.hxx:240
void ImplInitSettings()
Definition: ctrl.cxx:428
virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent &dtdee)
Definition: dndhelp.cxx:40
Definition: timer.hxx:26
virtual bool IsReadOnly() const
Definition: edit.hxx:190
virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent &dtde)
Definition: dndhelp.cxx:36
virtual void Command(const CommandEvent &rCEvt)
Definition: window.cxx:1886
sal_Int32 mnWidthInChars
Definition: edit.hxx:74
TextFilter * mpFilterText
Definition: edit.hxx:63
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
bool IsPassword() const
Definition: edit.hxx:273
bool IsValueChangedFromSaved() const
Definition: edit.hxx:229