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 <rtl/ustrbuf.hxx>
29 #include <o3tl/deleter.hxx>
30 #include <tools/solar.h>
31 #include <vcl/dllapi.h>
32 #include <vcl/menu.hxx>
33 #include <vcl/dndhelp.hxx>
34 #include <vcl/vclptr.hxx>
35 #include <com/sun/star/uno/Reference.h>
36 
37 namespace com {
38 namespace sun {
39 namespace star {
40 namespace i18n {
41  class XBreakIterator;
42  class XExtendedInputSequenceChecker;
43 }}}}
44 namespace weld {
45  class Widget;
46 }
47 
48 class VclBuilder;
49 struct DDInfo;
50 struct Impl_IMEInfos;
51 
52 #define EDIT_NOLIMIT SAL_MAX_INT32
53 
54 class Timer;
55 
57 {
58 private:
61  std::unique_ptr<DDInfo, o3tl::default_delete<DDInfo>> mpDDInfo;
62  std::unique_ptr<Impl_IMEInfos> mpIMEInfos;
63  OUStringBuffer maText;
65  OUString maSaveValue;
66  OUString maUndoText;
67  long mnXOffset;
69  sal_uInt16 mnAlign;
70  sal_Int32 mnMaxTextLen;
71  sal_Int32 mnWidthInChars;
72  sal_Int32 mnMaxWidthChars;
74  bool mbModified: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, 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 SetInsertMode( bool bInsert );
183  bool IsInsertMode() const;
184 
185  virtual void SetMaxTextLen( sal_Int32 nMaxLen );
186  virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
187 
188  void SetWidthInChars(sal_Int32 nWidthInChars);
189  sal_Int32 GetWidthInChars() const { return mnWidthInChars; }
190 
191  void setMaxWidthChars(sal_Int32 nWidth);
192 
193  virtual void SetSelection( const Selection& rSelection );
194  virtual const Selection& GetSelection() const;
195 
196  virtual void ReplaceSelected( const OUString& rStr );
197  virtual void DeleteSelected();
198  virtual OUString GetSelected() const;
199 
200  virtual void Cut();
201  virtual void Copy();
202  virtual void Paste();
203  void Undo();
204 
205  virtual void SetText( const OUString& rStr ) override;
206  virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
207  virtual OUString GetText() const override;
208 
209  void SetCursorAtLast();
210 
211  void SetPlaceholderText( const OUString& rStr );
212 
213  void SaveValue() { maSaveValue = GetText(); }
214  const OUString& GetSavedValue() const { return maSaveValue; }
215  bool IsValueChangedFromSaved() const { return maSaveValue != GetText(); }
216 
217  virtual void SetModifyHdl( const Link<Edit&,void>& rLink ) { maModifyHdl = rLink; }
218  virtual const Link<Edit&,void>& GetModifyHdl() const { return maModifyHdl; }
219 
220  void SetActivateHdl(const Link<Edit&,bool>& rLink) { maActivateHdl = rLink; }
221 
222  void SetSubEdit( Edit* pEdit );
223  Edit* GetSubEdit() const { return mpSubEdit; }
224 
225  void SetAutocompleteHdl( const Link<Edit&,void>& rLink ) { maAutocompleteHdl = rLink; }
226  const Link<Edit&,void>& GetAutocompleteHdl() const { return maAutocompleteHdl; }
227 
228  virtual Size CalcMinimumSize() const;
229  virtual Size CalcMinimumSizeForText(const OUString &rString) const;
230  virtual Size GetOptimalSize() const override;
231  virtual Size CalcSize(sal_Int32 nChars) const;
232  sal_Int32 GetMaxVisChars() const;
233 
234  // shows a warning box saying "text too long, truncated"
235  static void ShowTruncationWarning(weld::Widget* pParent);
236 
237  VclPtr<PopupMenu> CreatePopupMenu();
238 
239  virtual OUString GetSurroundingText() const override;
240  virtual Selection GetSurroundingTextSelection() const override;
241  virtual bool set_property(const OString &rKey, const OUString &rValue) override;
242 
243  void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; }
244 
245  virtual FactoryFunction GetUITestFactory() const override;
246 
247  // returns the minimum size a bordered Edit should have given the current
248  // global style settings (needed by sc's inputwin.cxx)
249  static Size GetMinimumEditSize();
250 
251  void SetForceControlBackground(bool b) { mbForceControlBackground = b; }
252 
253  bool IsPassword() const { return mbPassword; }
254 };
255 
256 #endif // INCLUDED_VCL_EDIT_HXX
257 
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetActivateHdl(const Link< Edit &, bool > &rLink)
Definition: edit.hxx:220
sal_Int32 mnMaxWidthChars
Definition: edit.hxx:72
OUString maSaveValue
Definition: edit.hxx:65
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3910
sal_Int32 GetWidthInChars() const
Definition: edit.hxx:189
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:223
long mnXOffset
Definition: edit.hxx:67
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:213
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
OUString maPlaceholderText
Definition: edit.hxx:64
virtual void FillLayoutData() const
Definition: ctrl.cxx:80
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
void SetForceControlBackground(bool b)
Definition: edit.hxx:251
sal_uInt16 mnAlign
Definition: edit.hxx:69
css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mxDnDListener
Definition: edit.hxx:130
virtual const Link< Edit &, void > & GetModifyHdl() const
Definition: edit.hxx:218
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:310
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:217
Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, sidebar, etc.
Definition: builder.hxx:64
virtual void Tracking(const TrackingEvent &rTEvt)
Definition: window.cxx:1927
virtual sal_Int32 GetMaxTextLen() const
Definition: edit.hxx:186
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator
Definition: edit.hxx:88
const Link< Edit &, void > & GetAutocompleteHdl() const
Definition: edit.hxx:226
virtual OUString GetText() const
Definition: window.cxx:3085
sal_Int32 mnMaxTextLen
Definition: edit.hxx:70
Definition: edit.cxx:89
Definition: edit.hxx:56
OUString maUndoText
Definition: edit.hxx:66
virtual Selection GetSurroundingTextSelection() const
Definition: window.cxx:3816
std::unique_ptr< Impl_IMEInfos > mpIMEInfos
Definition: edit.hxx:62
OUStringBuffer maText
Definition: edit.hxx:63
Selection maSelection
Definition: edit.hxx:68
virtual OUString GetSurroundingText() const
Definition: window.cxx:3811
DrawFlags
Definition: window.hxx:353
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:74
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:302
exports com.sun.star. i18n
virtual void Draw(::OutputDevice *pDev, const Point &rPos, DrawFlags nFlags)
Definition: window.cxx:1824
sal_Unicode mcEchoChar
Definition: edit.hxx:73
void SetTextFilter(TextFilter *pFilter)
Definition: edit.hxx:243
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:1431
virtual void LoseFocus()
Definition: window.cxx:1850
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:1800
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:936
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:374
std::unique_ptr< DDInfo, o3tl::default_delete< DDInfo > > mpDDInfo
Definition: edit.hxx:61
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:1836
unsigned char sal_uInt8
Link< Edit &, bool > maActivateHdl
Definition: edit.hxx:85
const OUString & GetSavedValue() const
Definition: edit.hxx:214
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1019
virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent &dge)
Definition: dndhelp.cxx:28
VclPtr< Edit > mpSubEdit
Definition: edit.hxx:59
void SetAutocompleteHdl(const Link< Edit &, void > &rLink)
Definition: edit.hxx:225
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:1918
sal_Int32 mnWidthInChars
Definition: edit.hxx:71
TextFilter * mpFilterText
Definition: edit.hxx:60
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
bool IsPassword() const
Definition: edit.hxx:253
bool IsValueChangedFromSaved() const
Definition: edit.hxx:215