bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / vcl / edit.hxx
blobcaf759789bef1a32fdad1876bd4180eb4b887a13
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 <memory>
27 #include <o3tl/deleter.hxx>
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 }}}}
42 namespace weld {
43 class Widget;
46 class VclBuilder;
47 struct DDInfo;
48 struct Impl_IMEInfos;
50 #define EDIT_NOLIMIT SAL_MAX_INT32
51 #define EDIT_UPDATEDATA_TIMEOUT 350
53 typedef OUString (*FncGetSpecialChars)( vcl::Window* pWin, const vcl::Font& rFont );
55 class VCL_DLLPUBLIC TextFilter
57 private:
58 OUString sForbiddenChars;
59 public:
60 void SetForbiddenChars(const OUString& rSet) { sForbiddenChars = rSet; }
62 virtual OUString filter(const OUString &rText);
64 TextFilter(const OUString &rForbiddenChars = OUString(" "));
65 virtual ~TextFilter();
68 class Timer;
70 class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
72 private:
73 VclPtr<Edit> mpSubEdit;
74 std::unique_ptr<Timer> mpUpdateDataTimer;
75 TextFilter* mpFilterText;
76 std::unique_ptr<DDInfo, o3tl::default_delete<DDInfo>> mpDDInfo;
77 std::unique_ptr<Impl_IMEInfos> mpIMEInfos;
78 OUStringBuffer maText;
79 OUString maPlaceholderText;
80 OUString maSaveValue;
81 OUString maUndoText;
82 long mnXOffset;
83 Selection maSelection;
84 sal_uInt16 mnAlign;
85 sal_Int32 mnMaxTextLen;
86 sal_Int32 mnWidthInChars;
87 sal_Int32 mnMaxWidthChars;
88 sal_Unicode mcEchoChar;
89 bool mbModified:1,
90 mbSelectAllSingleClick:1,
91 mbInternModified:1,
92 mbReadOnly:1,
93 mbInsertMode:1,
94 mbClickedInSelection:1,
95 mbIsSubEdit:1,
96 mbActivePopup:1,
97 mbForceControlBackground:1,
98 mbPassword;
99 Link<Edit&,void> maModifyHdl;
100 Link<Edit&,void> maUpdateDataHdl;
101 Link<Edit&,void> maAutocompleteHdl;
102 Link<Edit&,bool> maActivateHdl;
103 std::unique_ptr<VclBuilder> mpUIBuilder;
105 css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC;
107 DECL_DLLPRIVATE_LINK(ImplUpdateDataHdl, Timer*, void);
109 SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const;
110 SAL_DLLPRIVATE void ImplInitEditData();
111 SAL_DLLPRIVATE void ImplModified();
112 SAL_DLLPRIVATE OUString ImplGetText() const;
113 SAL_DLLPRIVATE void ImplRepaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle);
114 SAL_DLLPRIVATE void ImplInvalidateOrRepaint();
115 SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
116 SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection );
117 SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = nullptr, bool bIsUserInput = false );
118 SAL_DLLPRIVATE static OUString ImplGetValidString( const OUString& rString );
119 SAL_DLLPRIVATE void ImplClearBackground(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle, long nXStart, long nXEnd);
120 SAL_DLLPRIVATE void ImplPaintBorder(vcl::RenderContext const & rRenderContext);
121 SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true );
122 SAL_DLLPRIVATE void ImplAlign();
123 SAL_DLLPRIVATE void ImplAlignAndPaint();
124 SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const;
125 SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect );
126 SAL_DLLPRIVATE void ImplShowDDCursor();
127 SAL_DLLPRIVATE void ImplHideDDCursor();
128 SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
129 SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
130 SAL_DLLPRIVATE void ImplCopy(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard);
131 SAL_DLLPRIVATE void ImplPaste(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard);
132 SAL_DLLPRIVATE long ImplGetTextYPosition() const;
133 SAL_DLLPRIVATE css::uno::Reference<css::i18n::XExtendedInputSequenceChecker > const & ImplGetInputSequenceChecker();
134 SAL_DLLPRIVATE static css::uno::Reference<css::i18n::XBreakIterator > ImplGetBreakIterator();
135 SAL_DLLPRIVATE void filterText();
137 protected:
138 using Control::ImplInitSettings;
139 using Window::ImplInit;
140 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
141 SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle );
142 SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true );
143 SAL_DLLPRIVATE ControlType ImplGetNativeControlType() const;
144 SAL_DLLPRIVATE long ImplGetExtraXOffset() const;
145 SAL_DLLPRIVATE long ImplGetExtraYOffset() const;
146 static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( vcl::Window* pWin );
148 css::uno::Reference<css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
150 // DragAndDropClient
151 using vcl::unohelper::DragAndDropClient::dragEnter;
152 using vcl::unohelper::DragAndDropClient::dragExit;
153 using vcl::unohelper::DragAndDropClient::dragOver;
154 virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override;
155 virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent& dsde) override;
156 virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override;
157 virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee) override;
158 virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) override;
159 virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override;
161 protected:
162 Edit(WindowType nType);
163 virtual void FillLayoutData() const override;
164 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
165 public:
166 // public because needed in button.cxx
167 SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext const & rRenderContext, WinBits nStyle);
169 Edit( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
170 virtual ~Edit() override;
171 virtual void dispose() override;
173 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
174 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
175 virtual void KeyInput( const KeyEvent& rKEvt ) override;
176 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
177 virtual void Resize() override;
178 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
179 virtual void GetFocus() override;
180 virtual void LoseFocus() override;
181 virtual void Tracking( const TrackingEvent& rTEvt ) override;
182 virtual void Command( const CommandEvent& rCEvt ) override;
183 virtual void StateChanged( StateChangedType nType ) override;
184 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
186 virtual void Modify();
187 virtual void UpdateData();
189 static bool IsCharInput( const KeyEvent& rKEvt );
191 virtual void SetModifyFlag();
192 virtual void ClearModifyFlag();
193 virtual bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
195 virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
196 virtual void DisableUpdateData();
198 void SetEchoChar( sal_Unicode c );
199 sal_Unicode GetEchoChar() const { return mcEchoChar; }
201 virtual void SetReadOnly( bool bReadOnly = true );
202 virtual bool IsReadOnly() const { return mbReadOnly; }
204 void SetSelectAllSingleClick( bool bSelectAllSingleClick );
205 bool IsSelectAllSingleClick() const { return mbSelectAllSingleClick; }
207 void SetInsertMode( bool bInsert );
208 bool IsInsertMode() const;
210 virtual void SetMaxTextLen( sal_Int32 nMaxLen );
211 virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
213 void SetWidthInChars(sal_Int32 nWidthInChars);
214 sal_Int32 GetWidthInChars() const { return mnWidthInChars; }
216 void setMaxWidthChars(sal_Int32 nWidth);
218 virtual void SetSelection( const Selection& rSelection );
219 virtual const Selection& GetSelection() const;
221 virtual void ReplaceSelected( const OUString& rStr );
222 virtual void DeleteSelected();
223 virtual OUString GetSelected() const;
225 virtual void Cut();
226 virtual void Copy();
227 virtual void Paste();
228 void Undo();
230 virtual void SetText( const OUString& rStr ) override;
231 virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
232 virtual OUString GetText() const override;
234 void SetCursorAtLast();
236 void SetPlaceholderText( const OUString& rStr );
237 OUString GetPlaceholderText() const;
239 void SaveValue() { maSaveValue = GetText(); }
240 const OUString& GetSavedValue() const { return maSaveValue; }
241 bool IsValueChangedFromSaved() const { return maSaveValue != GetText(); }
243 virtual void SetModifyHdl( const Link<Edit&,void>& rLink ) { maModifyHdl = rLink; }
244 virtual const Link<Edit&,void>& GetModifyHdl() const { return maModifyHdl; }
245 virtual void SetUpdateDataHdl( const Link<Edit&,void>& rLink ) { maUpdateDataHdl = rLink; }
247 void SetActivateHdl(const Link<Edit&,bool>& rLink) { maActivateHdl = rLink; }
249 void SetSubEdit( Edit* pEdit );
250 Edit* GetSubEdit() const { return mpSubEdit; }
252 void SetAutocompleteHdl( const Link<Edit&,void>& rLink ) { maAutocompleteHdl = rLink; }
253 const Link<Edit&,void>& GetAutocompleteHdl() const { return maAutocompleteHdl; }
255 virtual Size CalcMinimumSize() const;
256 virtual Size CalcMinimumSizeForText(const OUString &rString) const;
257 virtual Size GetOptimalSize() const override;
258 virtual Size CalcSize(sal_Int32 nChars) const;
259 sal_Int32 GetMaxVisChars() const;
261 sal_Int32 GetCharPos( const Point& rWindowPos ) const;
263 // shows a warning box saying "text too long, truncated"
264 static void ShowTruncationWarning(weld::Widget* pParent);
266 static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
267 static FncGetSpecialChars GetGetSpecialCharsFunction();
269 VclPtr<PopupMenu> CreatePopupMenu();
271 virtual OUString GetSurroundingText() const override;
272 virtual Selection GetSurroundingTextSelection() const override;
273 virtual bool set_property(const OString &rKey, const OUString &rValue) override;
275 void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; }
277 virtual FactoryFunction GetUITestFactory() const override;
279 // returns the minimum size a bordered Edit should have given the current
280 // global style settings (needed by sc's inputwin.cxx)
281 static Size GetMinimumEditSize();
283 void SetForceControlBackground(bool b) { mbForceControlBackground = b; }
285 bool IsPassword() const { return mbPassword; }
288 #endif // INCLUDED_VCL_EDIT_HXX
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */