/src/libreoffice/include/vcl/toolkit/edit.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) |
23 | | #error "don't use this in new code" |
24 | | #endif |
25 | | |
26 | | #include <vcl/ctrl.hxx> |
27 | | #include <vcl/textfilter.hxx> |
28 | | |
29 | | #include <memory> |
30 | | |
31 | | #include <rtl/ustrbuf.hxx> |
32 | | #include <o3tl/deleter.hxx> |
33 | | #include <vcl/dllapi.h> |
34 | | #include <vcl/dndhelp.hxx> |
35 | | #include <vcl/vclptr.hxx> |
36 | | #include <com/sun/star/uno/Reference.h> |
37 | | |
38 | | namespace com::sun::star::i18n { |
39 | | class XBreakIterator; |
40 | | class XExtendedInputSequenceChecker; |
41 | | } |
42 | | namespace weld { |
43 | | class Widget; |
44 | | } |
45 | | |
46 | | class PopupMenu; |
47 | | class VclBuilder; |
48 | | struct DragDropInfo; |
49 | | struct Impl_IMEInfos; |
50 | | |
51 | 0 | #define EDIT_NOLIMIT SAL_MAX_INT32 |
52 | | |
53 | | class Timer; |
54 | | |
55 | | class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient |
56 | | { |
57 | | private: |
58 | | VclPtr<Edit> mpSubEdit; |
59 | | TextFilter* mpFilterText; |
60 | | std::unique_ptr<DragDropInfo, o3tl::default_delete<DragDropInfo>> mpDDInfo; |
61 | | std::unique_ptr<Impl_IMEInfos> mpIMEInfos; |
62 | | OUStringBuffer maText; |
63 | | OUString maPlaceholderText; |
64 | | OUString maSaveValue; |
65 | | OUString maUndoText; |
66 | | tools::Long mnXOffset; |
67 | | Selection maSelection; |
68 | | sal_uInt16 mnAlign; |
69 | | sal_Int32 mnMaxTextLen; |
70 | | sal_Int32 mnWidthInChars; |
71 | | sal_Int32 mnMaxWidthChars; |
72 | | sal_Unicode mcEchoChar; |
73 | | bool mbInternModified:1, |
74 | | mbReadOnly:1, |
75 | | mbInsertMode:1, |
76 | | mbClickedInSelection:1, |
77 | | mbIsSubEdit:1, |
78 | | mbActivePopup:1, |
79 | | mbForceControlBackground:1, |
80 | | mbPassword; |
81 | | Link<Edit&,void> maModifyHdl; |
82 | | Link<Edit&,void> maAutocompleteHdl; |
83 | | Link<Edit&,bool> maActivateHdl; |
84 | | std::unique_ptr<VclBuilder> mpUIBuilder; |
85 | | sal_uInt8 maEntryMessageType; |
86 | | |
87 | | css::uno::Reference<css::i18n::XBreakIterator> mxBreakIterator; |
88 | | css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC; |
89 | | rtl::Reference<vcl::unohelper::DragAndDropWrapper> mxDnDListener; |
90 | | |
91 | | SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const; |
92 | | SAL_DLLPRIVATE void ImplInitEditData(); |
93 | | SAL_DLLPRIVATE OUString ImplGetText() const; |
94 | | SAL_DLLPRIVATE void ImplRepaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle); |
95 | | SAL_DLLPRIVATE void ImplInvalidateOrRepaint(); |
96 | | SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode ); |
97 | | SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection ); |
98 | | SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = nullptr, bool bIsUserInput = false ); |
99 | | SAL_DLLPRIVATE static OUString ImplGetValidString( const OUString& rString ); |
100 | | SAL_DLLPRIVATE void ImplClearBackground(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle, tools::Long nXStart, tools::Long nXEnd); |
101 | | SAL_DLLPRIVATE void ImplPaintBorder(vcl::RenderContext const & rRenderContext); |
102 | | SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true ); |
103 | | SAL_DLLPRIVATE void ImplAlign(); |
104 | | SAL_DLLPRIVATE void ImplAlignAndPaint(); |
105 | | SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const; |
106 | | SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect ); |
107 | | SAL_DLLPRIVATE void ImplShowDDCursor(); |
108 | | SAL_DLLPRIVATE void ImplHideDDCursor(); |
109 | | SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt ); |
110 | | SAL_DLLPRIVATE void ImplCopyToSelectionClipboard(); |
111 | | SAL_DLLPRIVATE void ImplCopy(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard); |
112 | | SAL_DLLPRIVATE void ImplPaste(css::uno::Reference<css::datatransfer::clipboard::XClipboard> const & rxClipboard); |
113 | | SAL_DLLPRIVATE tools::Long ImplGetTextYPosition() const; |
114 | | SAL_DLLPRIVATE css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> const& ImplGetInputSequenceChecker(); |
115 | | SAL_DLLPRIVATE css::uno::Reference<css::i18n::XBreakIterator> const& ImplGetBreakIterator(); |
116 | | SAL_DLLPRIVATE void filterText(); |
117 | | |
118 | | protected: |
119 | | using Control::ImplInitSettings; |
120 | | using Window::ImplInit; |
121 | | SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle ); |
122 | | SAL_DLLPRIVATE static WinBits ImplInitStyle( WinBits nStyle ); |
123 | | SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true ); |
124 | | SAL_DLLPRIVATE ControlType ImplGetNativeControlType() const; |
125 | | SAL_DLLPRIVATE tools::Long ImplGetExtraXOffset() const; |
126 | | SAL_DLLPRIVATE tools::Long ImplGetExtraYOffset() const; |
127 | | static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( vcl::Window* pWin ); |
128 | | |
129 | | // DragAndDropClient |
130 | | using vcl::unohelper::DragAndDropClient::dragEnter; |
131 | | using vcl::unohelper::DragAndDropClient::dragExit; |
132 | | using vcl::unohelper::DragAndDropClient::dragOver; |
133 | | virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override; |
134 | | virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent& dsde) override; |
135 | | virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override; |
136 | | virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee) override; |
137 | | virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte) override; |
138 | | virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override; |
139 | | |
140 | | protected: |
141 | | SAL_DLLPRIVATE Edit(WindowType eType); |
142 | | virtual void FillLayoutData() const override; |
143 | | virtual void ApplySettings(vcl::RenderContext& rRenderContext) override; |
144 | | public: |
145 | | // public because needed in button.cxx |
146 | | SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext const & rRenderContext, WinBits nStyle) const; |
147 | | |
148 | | Edit( vcl::Window* pParent, WinBits nStyle = WB_BORDER ); |
149 | | virtual ~Edit() override; |
150 | | virtual void dispose() override; |
151 | | |
152 | | virtual rtl::Reference<comphelper::OAccessible> CreateAccessible() override; |
153 | | |
154 | | virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; |
155 | | virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; |
156 | | virtual void KeyInput( const KeyEvent& rKEvt ) override; |
157 | | virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; |
158 | | virtual void Resize() override; |
159 | | virtual void Draw(OutputDevice& rDev, const Point& rPos, SystemTextColorFlags nFlags) override; |
160 | | virtual void GetFocus() override; |
161 | | virtual void LoseFocus() override; |
162 | | virtual void Tracking( const TrackingEvent& rTEvt ) override; |
163 | | virtual void Command( const CommandEvent& rCEvt ) override; |
164 | | virtual void StateChanged( StateChangedType nType ) override; |
165 | | virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; |
166 | | virtual bool PreNotify(NotifyEvent& rNEvt) override; |
167 | | |
168 | | virtual void Modify(); |
169 | | |
170 | | SAL_DLLPRIVATE static bool IsCharInput( const KeyEvent& rKEvt ); |
171 | | |
172 | | virtual void SetModifyFlag(); |
173 | | |
174 | | void SetEchoChar( sal_Unicode c ); |
175 | 0 | sal_Unicode GetEchoChar() const { return mcEchoChar; } |
176 | | |
177 | | virtual void SetReadOnly( bool bReadOnly = true ); |
178 | 0 | virtual bool IsReadOnly() const { return mbReadOnly; } |
179 | | |
180 | | SAL_DLLPRIVATE void SetInsertMode( bool bInsert ); |
181 | | SAL_DLLPRIVATE bool IsInsertMode() const; |
182 | | |
183 | | virtual void SetMaxTextLen( sal_Int32 nMaxLen ); |
184 | 0 | virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; } |
185 | | |
186 | | SAL_DLLPRIVATE void SetWidthInChars(sal_Int32 nWidthInChars); |
187 | 0 | sal_Int32 GetWidthInChars() const { return mnWidthInChars; } |
188 | | |
189 | | SAL_DLLPRIVATE void setMaxWidthChars(sal_Int32 nWidth); |
190 | | |
191 | | virtual void SetSelection( const Selection& rSelection ); |
192 | | virtual const Selection& GetSelection() const; |
193 | | |
194 | | virtual void ReplaceSelected( const OUString& rStr ); |
195 | | virtual void DeleteSelected(); |
196 | | virtual OUString GetSelected() const; |
197 | | |
198 | | virtual void Cut(); |
199 | | virtual void Copy(); |
200 | | virtual void Paste(); |
201 | | SAL_DLLPRIVATE void Undo(); |
202 | | |
203 | | virtual void SetText( const OUString& rStr ) override; |
204 | | virtual void SetText( const OUString& rStr, const Selection& rNewSelection ); |
205 | | virtual OUString GetText() const override; |
206 | | |
207 | | SAL_DLLPRIVATE void SetCursorAtLast(); |
208 | | |
209 | | SAL_DLLPRIVATE void SetPlaceholderText( const OUString& rStr ); |
210 | | |
211 | 0 | void SaveValue() { maSaveValue = GetText(); } |
212 | 0 | const OUString& GetSavedValue() const { return maSaveValue; } |
213 | | |
214 | 0 | virtual void SetModifyHdl( const Link<Edit&,void>& rLink ) { maModifyHdl = rLink; } |
215 | 0 | virtual const Link<Edit&,void>& GetModifyHdl() const { return maModifyHdl; } |
216 | | |
217 | 0 | void SetActivateHdl(const Link<Edit&,bool>& rLink) { maActivateHdl = rLink; } |
218 | | |
219 | | SAL_DLLPRIVATE void SetSubEdit( Edit* pEdit ); |
220 | 0 | Edit* GetSubEdit() const { return mpSubEdit; } |
221 | | |
222 | 0 | void SetAutocompleteHdl( const Link<Edit&,void>& rLink ) { maAutocompleteHdl = rLink; } |
223 | 0 | const Link<Edit&,void>& GetAutocompleteHdl() const { return maAutocompleteHdl; } |
224 | | |
225 | | virtual Size CalcMinimumSize() const; |
226 | | virtual Size CalcMinimumSizeForText(const OUString &rString) const; |
227 | | virtual Size GetOptimalSize() const override; |
228 | | virtual Size CalcSize(sal_Int32 nChars) const; |
229 | | sal_Int32 GetMaxVisChars() const; |
230 | | |
231 | | // shows a warning box saying "text too long, truncated" |
232 | | SAL_DLLPRIVATE static void ShowTruncationWarning(weld::Widget* pParent); |
233 | | |
234 | | SAL_DLLPRIVATE VclPtr<PopupMenu> CreatePopupMenu(); |
235 | | |
236 | | virtual OUString GetSurroundingText() const override; |
237 | | virtual Selection GetSurroundingTextSelection() const override; |
238 | | virtual bool DeleteSurroundingText(const Selection& rSelection) override; |
239 | | virtual bool set_property(const OUString &rKey, const OUString &rValue) override; |
240 | | |
241 | 0 | void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; } |
242 | | |
243 | | virtual FactoryFunction GetUITestFactory() const override; |
244 | | |
245 | 0 | void SetForceControlBackground(bool b) { mbForceControlBackground = b; } |
246 | | |
247 | 0 | bool IsPassword() const { return mbPassword; } |
248 | | |
249 | 0 | bool IsActivePopup() const { return mbActivePopup; } |
250 | | |
251 | 0 | void SetEntryMessageType(sal_uInt8 aEntryMessageType) { maEntryMessageType = aEntryMessageType; } |
252 | | }; |
253 | | |
254 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |