Line data Source code
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 _SV_EDIT_HXX
21 : #define _SV_EDIT_HXX
22 :
23 : #include <tools/solar.h>
24 : #include <vcl/dllapi.h>
25 : #include <vcl/timer.hxx>
26 : #include <vcl/ctrl.hxx>
27 : #include <vcl/menu.hxx>
28 : #include <vcl/dndhelp.hxx>
29 : #include <com/sun/star/uno/Reference.h>
30 :
31 : namespace com {
32 : namespace sun {
33 : namespace star {
34 : namespace i18n {
35 : class XBreakIterator;
36 : class XExtendedInputSequenceChecker;
37 : }}}}
38 :
39 : struct DDInfo;
40 : struct Impl_IMEInfos;
41 :
42 : // --------------
43 : // - Edit-Types -
44 : // --------------
45 :
46 : #define EDIT_NOLIMIT STRING_LEN
47 : #define EDIT_UPDATEDATA_TIMEOUT 350
48 :
49 : typedef XubString (*FncGetSpecialChars)( Window* pWin, const Font& rFont );
50 :
51 : // --------
52 : // - Edit -
53 : // --------
54 :
55 : enum AutocompleteAction{ AUTOCOMPLETE_KEYINPUT, AUTOCOMPLETE_TABFORWARD, AUTOCOMPLETE_TABBACKWARD };
56 :
57 : class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
58 : {
59 : private:
60 : Edit* mpSubEdit;
61 : Timer* mpUpdateDataTimer;
62 : DDInfo* mpDDInfo;
63 : Impl_IMEInfos* mpIMEInfos;
64 : OUStringBuffer maText;
65 : OUString maPlaceholderText;
66 : OUString maSaveValue;
67 : OUString maUndoText;
68 : OUString maRedoText;
69 : long mnXOffset;
70 : Selection maSelection;
71 : sal_uInt16 mnAlign;
72 : xub_StrLen mnMaxTextLen;
73 : sal_Int32 mnWidthInChars;
74 : sal_Int32 mnMaxWidthChars;
75 : AutocompleteAction meAutocompleteAction;
76 : sal_Unicode mcEchoChar;
77 : sal_Bool mbModified:1,
78 : mbInternModified:1,
79 : mbReadOnly:1,
80 : mbInsertMode:1,
81 : mbClickedInSelection:1,
82 : mbIsSubEdit:1,
83 : mbInMBDown:1,
84 : mbActivePopup:1;
85 : Link maModifyHdl;
86 : Link maUpdateDataHdl;
87 : Link maAutocompleteHdl;
88 :
89 : DECL_DLLPRIVATE_LINK( ImplUpdateDataHdl, void* );
90 :
91 : SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_uInt32 nSelectionLen ) const;
92 : SAL_DLLPRIVATE void ImplInitEditData();
93 : SAL_DLLPRIVATE void ImplModified();
94 : SAL_DLLPRIVATE OUString ImplGetText() const;
95 : SAL_DLLPRIVATE void ImplRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN, bool bLayout = false );
96 : SAL_DLLPRIVATE void ImplInvalidateOrRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN );
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 = 0 );
99 : SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = 0, sal_Bool bIsUserInput = sal_False );
100 : SAL_DLLPRIVATE OUString ImplGetValidString( const OUString& rString ) const;
101 : SAL_DLLPRIVATE void ImplClearBackground( long nXStart, long nXEnd );
102 : SAL_DLLPRIVATE void ImplPaintBorder( long nXStart, long nXEnd );
103 : SAL_DLLPRIVATE void ImplShowCursor( sal_Bool bOnlyIfVisible = sal_True );
104 : SAL_DLLPRIVATE void ImplAlign();
105 : SAL_DLLPRIVATE void ImplAlignAndPaint();
106 : SAL_DLLPRIVATE xub_StrLen ImplGetCharPos( const Point& rWindowPos ) const;
107 : SAL_DLLPRIVATE void ImplSetCursorPos( xub_StrLen nChar, sal_Bool bSelect );
108 : SAL_DLLPRIVATE void ImplShowDDCursor();
109 : SAL_DLLPRIVATE void ImplHideDDCursor();
110 : SAL_DLLPRIVATE sal_Bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
111 : SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
112 : SAL_DLLPRIVATE void ImplCopy( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
113 : SAL_DLLPRIVATE void ImplPaste( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
114 : SAL_DLLPRIVATE long ImplGetTextYPosition() const;
115 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker() const;
116 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > ImplGetBreakIterator() const;
117 :
118 : protected:
119 : using Control::ImplInitSettings;
120 : using Window::ImplInit;
121 : SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
122 : SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
123 : SAL_DLLPRIVATE void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
124 : SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
125 : SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, sal_Bool bPaint = sal_True );
126 : SAL_DLLPRIVATE int ImplGetNativeControlType() const;
127 : SAL_DLLPRIVATE long ImplGetExtraOffset() const;
128 : static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( Window* pWin );
129 :
130 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
131 :
132 : // DragAndDropClient
133 : using vcl::unohelper::DragAndDropClient::dragEnter;
134 : using vcl::unohelper::DragAndDropClient::dragExit;
135 : using vcl::unohelper::DragAndDropClient::dragOver;
136 : virtual void dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent& dge ) throw (::com::sun::star::uno::RuntimeException);
137 : virtual void dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& dsde ) throw (::com::sun::star::uno::RuntimeException);
138 : virtual void drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
139 : virtual void dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) throw (::com::sun::star::uno::RuntimeException);
140 : virtual void dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& dte ) throw (::com::sun::star::uno::RuntimeException);
141 : virtual void dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
142 :
143 : protected:
144 : virtual void FillLayoutData() const;
145 : Edit( WindowType nType );
146 :
147 : public:
148 : // public because needed in button.cxx
149 : SAL_DLLPRIVATE bool ImplUseNativeBorder( WinBits nStyle );
150 :
151 : Edit( Window* pParent, WinBits nStyle = WB_BORDER );
152 : Edit( Window* pParent, const ResId& rResId );
153 : virtual ~Edit();
154 :
155 : virtual void MouseButtonDown( const MouseEvent& rMEvt );
156 : virtual void MouseButtonUp( const MouseEvent& rMEvt );
157 : virtual void KeyInput( const KeyEvent& rKEvt );
158 : virtual void Paint( const Rectangle& rRect );
159 : virtual void Resize();
160 : virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
161 : virtual void GetFocus();
162 : virtual void LoseFocus();
163 : virtual void Tracking( const TrackingEvent& rTEvt );
164 : virtual void Command( const CommandEvent& rCEvt );
165 : virtual void StateChanged( StateChangedType nType );
166 : virtual void DataChanged( const DataChangedEvent& rDCEvt );
167 : virtual Window* GetPreferredKeyInputWindow();
168 :
169 : virtual void Modify();
170 : virtual void UpdateData();
171 :
172 : static sal_Bool IsCharInput( const KeyEvent& rKEvt );
173 :
174 : virtual void SetModifyFlag();
175 : virtual void ClearModifyFlag();
176 0 : virtual sal_Bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
177 :
178 : virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
179 0 : virtual void DisableUpdateData() { delete mpUpdateDataTimer; mpUpdateDataTimer = NULL; }
180 : virtual sal_uLong IsUpdateDataEnabled() const;
181 :
182 : void SetEchoChar( sal_Unicode c );
183 11 : sal_Unicode GetEchoChar() const { return mcEchoChar; }
184 :
185 : virtual void SetReadOnly( sal_Bool bReadOnly = sal_True );
186 107 : virtual sal_Bool IsReadOnly() const { return mbReadOnly; }
187 :
188 : void SetInsertMode( sal_Bool bInsert );
189 : sal_Bool IsInsertMode() const;
190 :
191 : virtual void SetMaxTextLen( xub_StrLen nMaxLen = EDIT_NOLIMIT );
192 0 : virtual xub_StrLen GetMaxTextLen() const { return mnMaxTextLen; }
193 :
194 : void SetWidthInChars(sal_Int32 nWidthInChars);
195 : sal_Int32 GetWidthInChars() const { return mnWidthInChars; }
196 :
197 : void setMaxWidthChars(sal_Int32 nWidth);
198 :
199 : virtual void SetSelection( const Selection& rSelection );
200 : virtual const Selection& GetSelection() const;
201 :
202 : virtual void ReplaceSelected( const OUString& rStr );
203 : virtual void DeleteSelected();
204 : virtual OUString GetSelected() const;
205 :
206 : virtual void Cut();
207 : virtual void Copy();
208 : virtual void Paste();
209 : void Undo();
210 :
211 : virtual void SetText( const OUString& rStr );
212 : virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
213 : virtual OUString GetText() const;
214 :
215 : virtual void SetPlaceholderText( const OUString& rStr );
216 : virtual OUString GetPlaceholderText() const;
217 :
218 6058 : void SaveValue() { maSaveValue = GetText(); }
219 0 : const OUString& GetSavedValue() const { return maSaveValue; }
220 :
221 14 : virtual void SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; }
222 0 : virtual const Link& GetModifyHdl() const { return maModifyHdl; }
223 0 : virtual void SetUpdateDataHdl( const Link& rLink ) { maUpdateDataHdl = rLink; }
224 :
225 : void SetSubEdit( Edit* pEdit );
226 4310 : Edit* GetSubEdit() const { return mpSubEdit; }
227 :
228 : void SetAutocompleteHdl( const Link& rHdl );
229 0 : const Link& GetAutocompleteHdl() const { return maAutocompleteHdl; }
230 0 : AutocompleteAction GetAutocompleteAction() const { return meAutocompleteAction; }
231 :
232 : virtual Size CalcMinimumSize() const;
233 : virtual Size CalcMinimumSizeForText(const OUString &rString) const;
234 : virtual Size GetOptimalSize() const;
235 : virtual Size CalcSize( sal_uInt16 nChars ) const;
236 : virtual xub_StrLen GetMaxVisChars() const;
237 :
238 : xub_StrLen GetCharPos( const Point& rWindowPos ) const;
239 :
240 : // shows a warning box saying "text too long, truncated"
241 : static void ShowTruncationWarning( Window* pParent );
242 :
243 : static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
244 : static FncGetSpecialChars GetGetSpecialCharsFunction();
245 :
246 : static PopupMenu* CreatePopupMenu();
247 : static void DeletePopupMenu( PopupMenu* pMenu );
248 :
249 : virtual OUString GetSurroundingText() const;
250 : virtual Selection GetSurroundingTextSelection() const;
251 : virtual bool set_property(const OString &rKey, const OString &rValue);
252 :
253 : // returns the minimum size a bordered Edit should have given the current
254 : // global style settings (needed by sc's inputwin.cxx)
255 : static Size GetMinimumEditSize();
256 : };
257 :
258 0 : inline sal_uLong Edit::IsUpdateDataEnabled() const
259 : {
260 0 : if ( mpUpdateDataTimer )
261 0 : return mpUpdateDataTimer->GetTimeout();
262 : else
263 0 : return sal_False;
264 : }
265 :
266 : #endif // _SV_EDIT_HXX
267 :
268 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|