Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / edit.hxx
blobfd84f1d3d7cdbbff3912f509cc660ec5fb7080cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_EDIT_HXX
21 #define INCLUDED_VCL_EDIT_HXX
23 #include <vcl/ctrl.hxx>
25 #include <functional>
26 #include <memory>
28 #include <tools/solar.h>
29 #include <vcl/dllapi.h>
30 #include <vcl/menu.hxx>
31 #include <vcl/dndhelp.hxx>
32 #include <vcl/vclptr.hxx>
33 #include <com/sun/star/uno/Reference.h>
35 namespace com {
36 namespace sun {
37 namespace star {
38 namespace i18n {
39 class XBreakIterator;
40 class XExtendedInputSequenceChecker;
41 }}}}
43 struct DDInfo;
44 struct Impl_IMEInfos;
47 #define EDIT_NOLIMIT SAL_MAX_INT32
48 #define EDIT_UPDATEDATA_TIMEOUT 350
50 typedef OUString (*FncGetSpecialChars)( vcl::Window* pWin, const vcl::Font& rFont );
52 class VCL_DLLPUBLIC TextFilter
54 private:
55 OUString sForbiddenChars;
56 public:
57 void SetForbiddenChars(const OUString& rSet) { sForbiddenChars = rSet; }
59 virtual OUString filter(const OUString &rText);
61 TextFilter(const OUString &rForbiddenChars = OUString(" "));
62 virtual ~TextFilter();
65 class Timer;
67 class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
69 private:
70 VclPtr<Edit> mpSubEdit;
71 Timer* mpUpdateDataTimer;
72 TextFilter* mpFilterText;
73 DDInfo* mpDDInfo;
74 Impl_IMEInfos* mpIMEInfos;
75 OUStringBuffer maText;
76 OUString maPlaceholderText;
77 OUString maSaveValue;
78 OUString maUndoText;
79 long mnXOffset;
80 Selection maSelection;
81 sal_uInt16 mnAlign;
82 sal_Int32 mnMaxTextLen;
83 sal_Int32 mnWidthInChars;
84 sal_Int32 mnMaxWidthChars;
85 sal_Unicode mcEchoChar;
86 bool mbModified:1,
87 mbInternModified:1,
88 mbReadOnly:1,
89 mbInsertMode:1,
90 mbClickedInSelection:1,
91 mbIsSubEdit:1,
92 mbInMBDown:1,
93 mbActivePopup:1;
94 Link<Edit&,void> maModifyHdl;
95 Link<Edit&,void> maUpdateDataHdl;
96 Link<Edit&,void> maAutocompleteHdl;
97 std::unique_ptr<VclBuilder> mpUIBuilder;
99 css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC;
101 DECL_DLLPRIVATE_LINK(ImplUpdateDataHdl, Timer*, void);
103 SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const;
104 SAL_DLLPRIVATE void ImplInitEditData();
105 SAL_DLLPRIVATE void ImplModified();
106 SAL_DLLPRIVATE OUString ImplGetText() const;
107 SAL_DLLPRIVATE void ImplRepaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle);
108 SAL_DLLPRIVATE void ImplInvalidateOrRepaint();
109 SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
110 SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection );
111 SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = nullptr, bool bIsUserInput = false );
112 SAL_DLLPRIVATE static OUString ImplGetValidString( const OUString& rString );
113 SAL_DLLPRIVATE void ImplClearBackground(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle, long nXStart, long nXEnd);
114 SAL_DLLPRIVATE void ImplPaintBorder(vcl::RenderContext& rRenderContext, long nXStart, long nXEnd);
115 SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true );
116 SAL_DLLPRIVATE void ImplAlign();
117 SAL_DLLPRIVATE void ImplAlignAndPaint();
118 SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const;
119 SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect );
120 SAL_DLLPRIVATE void ImplShowDDCursor();
121 SAL_DLLPRIVATE void ImplHideDDCursor();
122 SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
123 SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
124 SAL_DLLPRIVATE void ImplCopy(css::uno::Reference<css::datatransfer::clipboard::XClipboard>& rxClipboard);
125 SAL_DLLPRIVATE void ImplPaste(css::uno::Reference<css::datatransfer::clipboard::XClipboard>& rxClipboard);
126 SAL_DLLPRIVATE long ImplGetTextYPosition() const;
127 SAL_DLLPRIVATE css::uno::Reference<css::i18n::XExtendedInputSequenceChecker > const & ImplGetInputSequenceChecker();
128 SAL_DLLPRIVATE static css::uno::Reference<css::i18n::XBreakIterator > ImplGetBreakIterator();
129 SAL_DLLPRIVATE void filterText();
131 protected:
132 using Control::ImplInitSettings;
133 using Window::ImplInit;
134 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
135 SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
136 SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true );
137 SAL_DLLPRIVATE ControlType ImplGetNativeControlType() const;
138 SAL_DLLPRIVATE long ImplGetExtraXOffset() const;
139 SAL_DLLPRIVATE long ImplGetExtraYOffset() const;
140 static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( vcl::Window* pWin );
142 css::uno::Reference<css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
144 // DragAndDropClient
145 using vcl::unohelper::DragAndDropClient::dragEnter;
146 using vcl::unohelper::DragAndDropClient::dragExit;
147 using vcl::unohelper::DragAndDropClient::dragOver;
148 virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override;
149 virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent& dsde) override;
150 virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override;
151 virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee) override;
152 virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) override;
153 virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override;
155 protected:
156 Edit(WindowType nType);
157 virtual void FillLayoutData() const override;
158 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
159 public:
160 // public because needed in button.cxx
161 SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext& rRenderContext, WinBits nStyle);
163 Edit( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
164 virtual ~Edit() override;
165 virtual void dispose() override;
167 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
168 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
169 virtual void KeyInput( const KeyEvent& rKEvt ) override;
170 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
171 virtual void Resize() override;
172 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
173 virtual void GetFocus() override;
174 virtual void LoseFocus() override;
175 virtual void Tracking( const TrackingEvent& rTEvt ) override;
176 virtual void Command( const CommandEvent& rCEvt ) override;
177 virtual void StateChanged( StateChangedType nType ) override;
178 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
180 virtual void Modify();
181 virtual void UpdateData();
183 static bool IsCharInput( const KeyEvent& rKEvt );
185 virtual void SetModifyFlag();
186 virtual void ClearModifyFlag();
187 virtual bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
189 virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
190 virtual void DisableUpdateData();
192 void SetEchoChar( sal_Unicode c );
193 sal_Unicode GetEchoChar() const { return mcEchoChar; }
195 virtual void SetReadOnly( bool bReadOnly = true );
196 virtual bool IsReadOnly() const { return mbReadOnly; }
198 void SetInsertMode( bool bInsert );
199 bool IsInsertMode() const;
201 virtual void SetMaxTextLen( sal_Int32 nMaxLen );
202 virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
204 void SetWidthInChars(sal_Int32 nWidthInChars);
206 void setMaxWidthChars(sal_Int32 nWidth);
208 virtual void SetSelection( const Selection& rSelection );
209 virtual const Selection& GetSelection() const;
211 virtual void ReplaceSelected( const OUString& rStr );
212 virtual void DeleteSelected();
213 virtual OUString GetSelected() const;
215 virtual void Cut();
216 virtual void Copy();
217 virtual void Paste();
218 void Undo();
220 virtual void SetText( const OUString& rStr ) override;
221 virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
222 virtual OUString GetText() const override;
224 void SetCursorAtLast();
226 void SetPlaceholderText( const OUString& rStr );
227 OUString GetPlaceholderText() const;
229 void SaveValue() { maSaveValue = GetText(); }
230 const OUString& GetSavedValue() const { return maSaveValue; }
231 bool IsValueChangedFromSaved() const { return maSaveValue != GetText(); }
233 virtual void SetModifyHdl( const Link<Edit&,void>& rLink ) { maModifyHdl = rLink; }
234 virtual const Link<Edit&,void>& GetModifyHdl() const { return maModifyHdl; }
235 virtual void SetUpdateDataHdl( const Link<Edit&,void>& rLink ) { maUpdateDataHdl = rLink; }
237 void SetSubEdit( Edit* pEdit );
238 Edit* GetSubEdit() const { return mpSubEdit; }
240 void SetAutocompleteHdl( const Link<Edit&,void>& rLink ) { maAutocompleteHdl = rLink; }
241 const Link<Edit&,void>& GetAutocompleteHdl() const { return maAutocompleteHdl; }
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;
249 sal_Int32 GetCharPos( const Point& rWindowPos ) const;
251 // shows a warning box saying "text too long, truncated"
252 static void ShowTruncationWarning( vcl::Window* pParent );
254 static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
255 static FncGetSpecialChars GetGetSpecialCharsFunction();
257 VclPtr<PopupMenu> CreatePopupMenu();
259 virtual OUString GetSurroundingText() const override;
260 virtual Selection GetSurroundingTextSelection() const override;
261 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
263 void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; }
265 virtual FactoryFunction GetUITestFactory() const override;
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();
272 #endif // INCLUDED_VCL_EDIT_HXX
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */