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 
53 class Timer;
54 
56 {
57 private:
60  std::unique_ptr<DDInfo, o3tl::default_delete<DDInfo>> mpDDInfo;
61  std::unique_ptr<Impl_IMEInfos> mpIMEInfos;
62  OUStringBuffer maText;
64  OUString maSaveValue;
65  OUString maUndoText;
66  long mnXOffset;
68  sal_uInt16 mnAlign;
69  sal_Int32 mnMaxTextLen;
70  sal_Int32 mnWidthInChars;
71  sal_Int32 mnMaxWidthChars;
73  bool mbModified:1,
74  mbSelectAllSingleClick:1,
75  mbInternModified:1,
76  mbReadOnly:1,
77  mbInsertMode:1,
78  mbClickedInSelection:1,
79  mbIsSubEdit:1,
80  mbActivePopup:1,
81  mbForceControlBackground:1,
82  mbPassword;
86  std::unique_ptr<VclBuilder> mpUIBuilder;
87 
88  css::uno::Reference<css::i18n::XBreakIterator> mxBreakIterator;
89  css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC;
90 
91  SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const;
92  SAL_DLLPRIVATE void ImplInitEditData();
93  SAL_DLLPRIVATE void ImplModified();
94  SAL_DLLPRIVATE OUString ImplGetText() const;
95  SAL_DLLPRIVATE void ImplRepaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle);
96  SAL_DLLPRIVATE void ImplInvalidateOrRepaint();
97  SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
98  SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection );
99  SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = nullptr, bool bIsUserInput = false );
100  SAL_DLLPRIVATE static OUString ImplGetValidString( const OUString& rString );
101  SAL_DLLPRIVATE void ImplClearBackground(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle, long nXStart, long nXEnd);
102  SAL_DLLPRIVATE void ImplPaintBorder(vcl::RenderContext const & rRenderContext);
103  SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true );
104  SAL_DLLPRIVATE void ImplAlign();
105  SAL_DLLPRIVATE void ImplAlignAndPaint();
106  SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const;
107  SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect );
108  SAL_DLLPRIVATE void ImplShowDDCursor();
109  SAL_DLLPRIVATE void ImplHideDDCursor();
110  SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
111  SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
112  SAL_DLLPRIVATE void ImplCopy(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard);
113  SAL_DLLPRIVATE void ImplPaste(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard);
114  SAL_DLLPRIVATE long ImplGetTextYPosition() const;
115  SAL_DLLPRIVATE css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> const& ImplGetInputSequenceChecker();
116  SAL_DLLPRIVATE css::uno::Reference<css::i18n::XBreakIterator> const& ImplGetBreakIterator();
117  SAL_DLLPRIVATE void filterText();
118 
119 protected:
121  using Window::ImplInit;
122  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
123  SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
124  SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true );
125  SAL_DLLPRIVATE ControlType ImplGetNativeControlType() const;
126  SAL_DLLPRIVATE long ImplGetExtraXOffset() const;
127  SAL_DLLPRIVATE long ImplGetExtraYOffset() const;
128  static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( vcl::Window* pWin );
129 
130  css::uno::Reference<css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
131 
132  // DragAndDropClient
136  virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override;
137  virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent& dsde) override;
138  virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override;
139  virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee) override;
140  virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) override;
141  virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override;
142 
143 protected:
144  Edit(WindowType nType);
145  virtual void FillLayoutData() const override;
146  virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
147 public:
148  // public because needed in button.cxx
149  SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext const & rRenderContext, WinBits nStyle);
150 
151  Edit( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
152  virtual ~Edit() override;
153  virtual void dispose() override;
154 
155  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
156  virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
157  virtual void KeyInput( const KeyEvent& rKEvt ) override;
158  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
159  virtual void Resize() override;
160  virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
161  virtual void GetFocus() override;
162  virtual void LoseFocus() override;
163  virtual void Tracking( const TrackingEvent& rTEvt ) override;
164  virtual void Command( const CommandEvent& rCEvt ) override;
165  virtual void StateChanged( StateChangedType nType ) override;
166  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
167 
168  virtual void Modify();
169 
170  static bool IsCharInput( const KeyEvent& rKEvt );
171 
172  virtual void SetModifyFlag();
173  virtual void ClearModifyFlag();
174  virtual bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
175 
176  void SetEchoChar( sal_Unicode c );
177  sal_Unicode GetEchoChar() const { return mcEchoChar; }
178 
179  virtual void SetReadOnly( bool bReadOnly = true );
180  virtual bool IsReadOnly() const { return mbReadOnly; }
181 
182  void SetSelectAllSingleClick( bool bSelectAllSingleClick );
183 
184  void SetInsertMode( bool bInsert );
185  bool IsInsertMode() const;
186 
187  virtual void SetMaxTextLen( sal_Int32 nMaxLen );
188  virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
189 
190  void SetWidthInChars(sal_Int32 nWidthInChars);
191  sal_Int32 GetWidthInChars() const { return mnWidthInChars; }
192 
193  void setMaxWidthChars(sal_Int32 nWidth);
194 
195  virtual void SetSelection( const Selection& rSelection );
196  virtual const Selection& GetSelection() const;
197 
198  virtual void ReplaceSelected( const OUString& rStr );
199  virtual void DeleteSelected();
200  virtual OUString GetSelected() const;
201 
202  virtual void Cut();
203  virtual void Copy();
204  virtual void Paste();
205  void Undo();
206 
207  virtual void SetText( const OUString& rStr ) override;
208  virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
209  virtual OUString GetText() const override;
210 
211  void SetCursorAtLast();
212 
213  void SetPlaceholderText( const OUString& rStr );
214 
215  void SaveValue() { maSaveValue = GetText(); }
216  const OUString& GetSavedValue() const { return maSaveValue; }
217  bool IsValueChangedFromSaved() const { return maSaveValue != GetText(); }
218 
219  virtual void SetModifyHdl( const Link<Edit&,void>& rLink ) { maModifyHdl = rLink; }
220  virtual const Link<Edit&,void>& GetModifyHdl() const { return maModifyHdl; }
221 
222  void SetActivateHdl(const Link<Edit&,bool>& rLink) { maActivateHdl = rLink; }
223 
224  void SetSubEdit( Edit* pEdit );
225  Edit* GetSubEdit() const { return mpSubEdit; }
226 
227  void SetAutocompleteHdl( const Link<Edit&,void>& rLink ) { maAutocompleteHdl = rLink; }
228  const Link<Edit&,void>& GetAutocompleteHdl() const { return maAutocompleteHdl; }
229 
230  virtual Size CalcMinimumSize() const;
231  virtual Size CalcMinimumSizeForText(const OUString &rString) const;
232  virtual Size GetOptimalSize() const override;
233  virtual Size CalcSize(sal_Int32 nChars) const;
234  sal_Int32 GetMaxVisChars() const;
235 
236  // shows a warning box saying "text too long, truncated"
237  static void ShowTruncationWarning(weld::Widget* pParent);
238 
239  VclPtr<PopupMenu> CreatePopupMenu();
240 
241  virtual OUString GetSurroundingText() const override;
242  virtual Selection GetSurroundingTextSelection() const override;
243  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
244 
245  void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; }
246 
247  virtual FactoryFunction GetUITestFactory() const override;
248 
249  // returns the minimum size a bordered Edit should have given the current
250  // global style settings (needed by sc's inputwin.cxx)
251  static Size GetMinimumEditSize();
252 
253  void SetForceControlBackground(bool b) { mbForceControlBackground = b; }
254 
255  bool IsPassword() const { return mbPassword; }
256 };
257 
258 #endif // INCLUDED_VCL_EDIT_HXX
259 
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetActivateHdl(const Link< Edit &, bool > &rLink)
Definition: edit.hxx:222
sal_Int32 mnMaxWidthChars
Definition: edit.hxx:71
OUString maSaveValue
Definition: edit.hxx:64
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3943
sal_Int32 GetWidthInChars() const
Definition: edit.hxx:191
void GetSelection(struct ESelection &rSel, SvxTextForwarder const *pForwarder)
Link< Edit &, void > maModifyHdl
Definition: edit.hxx:83
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:414
sal_Unicode GetEchoChar() const
Definition: edit.hxx:177
Edit * GetSubEdit() const
Definition: edit.hxx:225
long mnXOffset
Definition: edit.hxx:66
virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent &dte)
Definition: dndhelp.cxx:44
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
void SaveValue()
Definition: edit.hxx:215
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
OUString maPlaceholderText
Definition: edit.hxx:63
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
void SetForceControlBackground(bool b)
Definition: edit.hxx:253
sal_uInt16 mnAlign
Definition: edit.hxx:68
css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mxDnDListener
Definition: edit.hxx:130
virtual const Link< Edit &, void > & GetModifyHdl() const
Definition: edit.hxx:220
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
Definition: ctrl.cxx:418
virtual bool IsModified() const
Definition: edit.hxx:174
virtual void MouseButtonUp(const MouseEvent &rMEvt)
Definition: mouse.cxx:421
StateChangedType
Definition: window.hxx:311
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:219
virtual void Tracking(const TrackingEvent &rTEvt)
Definition: window.cxx:1946
virtual sal_Int32 GetMaxTextLen() const
Definition: edit.hxx:188
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator
Definition: edit.hxx:88
const Link< Edit &, void > & GetAutocompleteHdl() const
Definition: edit.hxx:228
virtual OUString GetText() const
Definition: window.cxx:3110
sal_Int32 mnMaxTextLen
Definition: edit.hxx:69
Definition: edit.cxx:88
Definition: edit.hxx:55
OUString maUndoText
Definition: edit.hxx:65
virtual Selection GetSurroundingTextSelection() const
Definition: window.cxx:3849
std::unique_ptr< Impl_IMEInfos > mpIMEInfos
Definition: edit.hxx:61
virtual void Draw(::OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags)
Definition: window.cxx:1843
OUStringBuffer maText
Definition: edit.hxx:62
Selection maSelection
Definition: edit.hxx:67
virtual OUString GetSurroundingText() const
Definition: window.cxx:3844
DrawFlags
Definition: window.hxx:354
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:73
std::unique_ptr< VclBuilder > mpUIBuilder
Definition: edit.hxx:86
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:72
void SetTextFilter(TextFilter *pFilter)
Definition: edit.hxx:245
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:1432
virtual void LoseFocus()
Definition: window.cxx:1869
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:1819
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:932
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
std::unique_ptr< DDInfo, o3tl::default_delete< DDInfo > > mpDDInfo
Definition: edit.hxx:60
css::uno::Reference< css::i18n::XExtendedInputSequenceChecker > mxISC
Definition: edit.hxx:89
Link< Edit &, void > maAutocompleteHdl
Definition: edit.hxx:84
virtual void Resize() override
Definition: ctrl.cxx:74
WindowType
Definition: ctrl.hxx:33
virtual void GetFocus()
Definition: window.cxx:1855
unsigned char sal_uInt8
Link< Edit &, bool > maActivateHdl
Definition: edit.hxx:85
const OUString & GetSavedValue() const
Definition: edit.hxx:216
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1017
virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent &dge)
Definition: dndhelp.cxx:28
VclPtr< Edit > mpSubEdit
Definition: edit.hxx:58
void SetAutocompleteHdl(const Link< Edit &, void > &rLink)
Definition: edit.hxx:227
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:180
virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent &dtde)
Definition: dndhelp.cxx:36
virtual void Command(const CommandEvent &rCEvt)
Definition: window.cxx:1937
sal_Int32 mnWidthInChars
Definition: edit.hxx:70
TextFilter * mpFilterText
Definition: edit.hxx:59
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
bool IsPassword() const
Definition: edit.hxx:255
bool IsValueChangedFromSaved() const
Definition: edit.hxx:217