Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / edit.hxx
blob80f5c562b0f3ce1ab2470f229e1a947b6b7d7564
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 <boost/signals2/signal.hpp>
24 #include <tools/solar.h>
25 #include <vcl/dllapi.h>
26 #include <vcl/timer.hxx>
27 #include <vcl/idle.hxx>
28 #include <vcl/ctrl.hxx>
29 #include <vcl/menu.hxx>
30 #include <vcl/dndhelp.hxx>
31 #include <vcl/vclptr.hxx>
32 #include <com/sun/star/uno/Reference.h>
34 namespace com {
35 namespace sun {
36 namespace star {
37 namespace i18n {
38 class XBreakIterator;
39 class XExtendedInputSequenceChecker;
40 }}}}
42 struct DDInfo;
43 struct Impl_IMEInfos;
46 // - Edit-Types -
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; }
58 const OUString& GetForbiddenChars() { return sForbiddenChars; }
60 virtual OUString filter(const OUString &rText);
62 TextFilter(const OUString &rForbiddenChars = OUString(" "));
63 virtual ~TextFilter();
66 enum AutocompleteAction{ AUTOCOMPLETE_KEYINPUT, AUTOCOMPLETE_TABFORWARD, AUTOCOMPLETE_TABBACKWARD };
68 // - Edit -
69 class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
71 private:
72 VclPtr<Edit> mpSubEdit;
73 Timer* mpUpdateDataTimer;
74 TextFilter* mpFilterText;
75 DDInfo* mpDDInfo;
76 Impl_IMEInfos* mpIMEInfos;
77 OUStringBuffer maText;
78 OUString maPlaceholderText;
79 OUString maSaveValue;
80 OUString maUndoText;
81 long mnXOffset;
82 Selection maSelection;
83 sal_uInt16 mnAlign;
84 sal_Int32 mnMaxTextLen;
85 sal_Int32 mnWidthInChars;
86 sal_Int32 mnMaxWidthChars;
87 AutocompleteAction meAutocompleteAction;
88 sal_Unicode mcEchoChar;
89 bool mbModified:1,
90 mbInternModified:1,
91 mbReadOnly:1,
92 mbInsertMode:1,
93 mbClickedInSelection:1,
94 mbIsSubEdit:1,
95 mbInMBDown:1,
96 mbActivePopup:1;
97 Link<> maModifyHdl;
98 Link<> maUpdateDataHdl;
100 css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC;
102 DECL_DLLPRIVATE_LINK_TYPED(ImplUpdateDataHdl, Timer*, void);
104 SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const;
105 SAL_DLLPRIVATE void ImplInitEditData();
106 SAL_DLLPRIVATE void ImplModified();
107 SAL_DLLPRIVATE OUString ImplGetText() const;
108 SAL_DLLPRIVATE void ImplRepaint(vcl::RenderContext& rRenderContext, const Rectangle& rRectangle, bool bLayout = false);
109 SAL_DLLPRIVATE void ImplInvalidateOrRepaint();
110 SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
111 SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection = 0 );
112 SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = 0, bool bIsUserInput = false );
113 SAL_DLLPRIVATE OUString ImplGetValidString( const OUString& rString ) const;
114 SAL_DLLPRIVATE void ImplClearBackground(vcl::RenderContext& rRenderContext, const Rectangle& rRectangle, long nXStart, long nXEnd);
115 SAL_DLLPRIVATE void ImplPaintBorder(vcl::RenderContext& rRenderContext, long nXStart, long nXEnd);
116 SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true );
117 SAL_DLLPRIVATE void ImplAlign();
118 SAL_DLLPRIVATE void ImplAlignAndPaint();
119 SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const;
120 SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect );
121 SAL_DLLPRIVATE void ImplShowDDCursor();
122 SAL_DLLPRIVATE void ImplHideDDCursor();
123 SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
124 SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
125 SAL_DLLPRIVATE void ImplCopy(css::uno::Reference<css::datatransfer::clipboard::XClipboard>& rxClipboard);
126 SAL_DLLPRIVATE void ImplPaste(css::uno::Reference<css::datatransfer::clipboard::XClipboard>& rxClipboard);
127 SAL_DLLPRIVATE long ImplGetTextYPosition() const;
128 SAL_DLLPRIVATE css::uno::Reference<css::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker();
129 SAL_DLLPRIVATE css::uno::Reference<css::i18n::XBreakIterator > ImplGetBreakIterator() const;
130 SAL_DLLPRIVATE void filterText();
132 protected:
133 using Control::ImplInitSettings;
134 using Window::ImplInit;
135 SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
136 SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
137 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
138 SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true );
139 SAL_DLLPRIVATE int ImplGetNativeControlType() const;
140 SAL_DLLPRIVATE long ImplGetExtraXOffset() const;
141 SAL_DLLPRIVATE long ImplGetExtraYOffset() const;
142 static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( vcl::Window* pWin );
144 css::uno::Reference<css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
146 // DragAndDropClient
147 using vcl::unohelper::DragAndDropClient::dragEnter;
148 using vcl::unohelper::DragAndDropClient::dragExit;
149 using vcl::unohelper::DragAndDropClient::dragOver;
150 virtual void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge)
151 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 virtual void dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent& dsde)
153 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 virtual void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde)
155 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 virtual void dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee)
157 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 virtual void dragExit(const css::datatransfer::dnd::DropTargetEvent& dte)
159 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 virtual void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde)
161 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
163 protected:
164 Edit(WindowType nType);
165 virtual void FillLayoutData() const SAL_OVERRIDE;
166 virtual void ApplySettings(vcl::RenderContext& rRenderContext) SAL_OVERRIDE;
167 public:
168 // public because needed in button.cxx
169 SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext& rRenderContext, WinBits nStyle);
171 Edit( vcl::Window* pParent, WinBits nStyle = WB_BORDER );
172 Edit( vcl::Window* pParent, const ResId& rResId );
173 virtual ~Edit();
174 virtual void dispose() SAL_OVERRIDE;
176 virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
177 virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
178 virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
179 virtual void Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) SAL_OVERRIDE;
180 virtual void Resize() SAL_OVERRIDE;
181 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) SAL_OVERRIDE;
182 virtual void GetFocus() SAL_OVERRIDE;
183 virtual void LoseFocus() SAL_OVERRIDE;
184 virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
185 virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
186 virtual void StateChanged( StateChangedType nType ) SAL_OVERRIDE;
187 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
188 virtual vcl::Window* GetPreferredKeyInputWindow() SAL_OVERRIDE;
190 virtual void Modify();
191 virtual void UpdateData();
193 static bool IsCharInput( const KeyEvent& rKEvt );
195 virtual void SetModifyFlag();
196 virtual void ClearModifyFlag();
197 virtual bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
199 virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
200 virtual void DisableUpdateData() { delete mpUpdateDataTimer; mpUpdateDataTimer = NULL; }
202 void SetEchoChar( sal_Unicode c );
203 sal_Unicode GetEchoChar() const { return mcEchoChar; }
205 virtual void SetReadOnly( bool bReadOnly = true );
206 virtual bool IsReadOnly() const { return mbReadOnly; }
208 void SetInsertMode( bool bInsert );
209 bool IsInsertMode() const;
211 virtual void SetMaxTextLen( sal_Int32 nMaxLen = EDIT_NOLIMIT );
212 virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
214 void SetWidthInChars(sal_Int32 nWidthInChars);
215 sal_Int32 GetWidthInChars() const { return mnWidthInChars; }
217 void setMaxWidthChars(sal_Int32 nWidth);
219 virtual void SetSelection( const Selection& rSelection );
220 virtual const Selection& GetSelection() const;
222 virtual void ReplaceSelected( const OUString& rStr );
223 virtual void DeleteSelected();
224 virtual OUString GetSelected() const;
226 virtual void Cut();
227 virtual void Copy();
228 virtual void Paste();
229 void Undo();
231 virtual void SetText( const OUString& rStr ) SAL_OVERRIDE;
232 virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
233 virtual OUString GetText() const SAL_OVERRIDE;
235 void SetPlaceholderText( const OUString& rStr );
236 OUString GetPlaceholderText() const;
238 void SaveValue() { maSaveValue = GetText(); }
239 const OUString& GetSavedValue() const { return maSaveValue; }
240 bool IsValueChangedFromSaved() const { return maSaveValue != GetText(); }
242 virtual void SetModifyHdl( const Link<>& rLink ) { maModifyHdl = rLink; }
243 virtual const Link<>& GetModifyHdl() const { return maModifyHdl; }
244 virtual void SetUpdateDataHdl( const Link<>& rLink ) { maUpdateDataHdl = rLink; }
246 void SetSubEdit( Edit* pEdit );
247 Edit* GetSubEdit() const { return mpSubEdit; }
249 boost::signals2::signal< void ( Edit* ) > autocompleteSignal;
250 AutocompleteAction GetAutocompleteAction() const { return meAutocompleteAction; }
252 virtual Size CalcMinimumSize() const;
253 virtual Size CalcMinimumSizeForText(const OUString &rString) const;
254 virtual Size GetOptimalSize() const SAL_OVERRIDE;
255 virtual Size CalcSize(sal_Int32 nChars) const;
256 sal_Int32 GetMaxVisChars() const;
258 sal_Int32 GetCharPos( const Point& rWindowPos ) const;
260 // shows a warning box saying "text too long, truncated"
261 static void ShowTruncationWarning( vcl::Window* pParent );
263 static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
264 static FncGetSpecialChars GetGetSpecialCharsFunction();
266 static PopupMenu* CreatePopupMenu();
267 static void DeletePopupMenu( PopupMenu* pMenu );
269 virtual OUString GetSurroundingText() const SAL_OVERRIDE;
270 virtual Selection GetSurroundingTextSelection() const SAL_OVERRIDE;
271 virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
273 void SetTextFilter(TextFilter* pFilter) { mpFilterText = pFilter; }
275 // returns the minimum size a bordered Edit should have given the current
276 // global style settings (needed by sc's inputwin.cxx)
277 static Size GetMinimumEditSize();
280 #endif // INCLUDED_VCL_EDIT_HXX
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */