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