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 : XubString maText;
65 : OUString maPlaceholderText;
66 : XubString maSaveValue;
67 : XubString maUndoText;
68 : XubString maRedoText;
69 : long mnXOffset;
70 : Selection maSelection;
71 : sal_uInt16 mnAlign;
72 : xub_StrLen mnMaxTextLen;
73 : sal_Int32 mnWidthInChars;
74 : AutocompleteAction meAutocompleteAction;
75 : sal_Unicode mcEchoChar;
76 : sal_Bool mbModified:1,
77 : mbInternModified:1,
78 : mbReadOnly:1,
79 : mbInsertMode:1,
80 : mbClickedInSelection:1,
81 : mbIsSubEdit:1,
82 : mbInMBDown:1,
83 : mbActivePopup:1;
84 : Link maModifyHdl;
85 : Link maUpdateDataHdl;
86 : Link maAutocompleteHdl;
87 :
88 : DECL_DLLPRIVATE_LINK( ImplUpdateDataHdl, void* );
89 :
90 : SAL_DLLPRIVATE bool ImplTruncateToMaxLen( rtl::OUString&, sal_uInt32 nSelectionLen ) const;
91 : SAL_DLLPRIVATE void ImplInitEditData();
92 : SAL_DLLPRIVATE void ImplModified();
93 : SAL_DLLPRIVATE XubString ImplGetText() const;
94 : SAL_DLLPRIVATE void ImplRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN, bool bLayout = false );
95 : SAL_DLLPRIVATE void ImplInvalidateOrRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN );
96 : SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
97 : SAL_DLLPRIVATE void ImplSetText( const XubString& rStr, const Selection* pNewSelection = 0 );
98 : SAL_DLLPRIVATE void ImplInsertText( const rtl::OUString& rStr, const Selection* pNewSelection = 0, sal_Bool bIsUserInput = sal_False );
99 : SAL_DLLPRIVATE String ImplGetValidString( const String& rString ) const;
100 : SAL_DLLPRIVATE void ImplClearBackground( long nXStart, long nXEnd );
101 : SAL_DLLPRIVATE void ImplPaintBorder( long nXStart, long nXEnd );
102 : SAL_DLLPRIVATE void ImplShowCursor( sal_Bool bOnlyIfVisible = sal_True );
103 : SAL_DLLPRIVATE void ImplAlign();
104 : SAL_DLLPRIVATE void ImplAlignAndPaint();
105 : SAL_DLLPRIVATE xub_StrLen ImplGetCharPos( const Point& rWindowPos ) const;
106 : SAL_DLLPRIVATE void ImplSetCursorPos( xub_StrLen nChar, sal_Bool bSelect );
107 : SAL_DLLPRIVATE void ImplShowDDCursor();
108 : SAL_DLLPRIVATE void ImplHideDDCursor();
109 : SAL_DLLPRIVATE sal_Bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
110 : SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
111 : SAL_DLLPRIVATE void ImplCopy( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
112 : SAL_DLLPRIVATE void ImplPaste( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
113 : SAL_DLLPRIVATE long ImplGetTextYPosition() const;
114 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker() const;
115 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > ImplGetBreakIterator() const;
116 :
117 : protected:
118 : using Control::ImplInitSettings;
119 : using Window::ImplInit;
120 : SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
121 : SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
122 : SAL_DLLPRIVATE void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
123 : SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
124 : SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, sal_Bool bPaint = sal_True );
125 : SAL_DLLPRIVATE int ImplGetNativeControlType();
126 : SAL_DLLPRIVATE long ImplGetExtraOffset() const;
127 : static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( Window* pWin );
128 :
129 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
130 :
131 : // DragAndDropClient
132 : using vcl::unohelper::DragAndDropClient::dragEnter;
133 : using vcl::unohelper::DragAndDropClient::dragExit;
134 : using vcl::unohelper::DragAndDropClient::dragOver;
135 : virtual void dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent& dge ) throw (::com::sun::star::uno::RuntimeException);
136 : virtual void dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& dsde ) throw (::com::sun::star::uno::RuntimeException);
137 : virtual void drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
138 : virtual void dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) throw (::com::sun::star::uno::RuntimeException);
139 : virtual void dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& dte ) throw (::com::sun::star::uno::RuntimeException);
140 : virtual void dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
141 :
142 : protected:
143 : virtual void FillLayoutData() const;
144 : Edit( WindowType nType );
145 :
146 : public:
147 : // public because needed in button.cxx
148 : SAL_DLLPRIVATE bool ImplUseNativeBorder( WinBits nStyle );
149 :
150 : Edit( Window* pParent, WinBits nStyle = WB_BORDER );
151 : Edit( Window* pParent, const ResId& rResId );
152 : Edit( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabeledByRelation );
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 0 : sal_Unicode GetEchoChar() const { return mcEchoChar; }
184 :
185 : virtual void SetReadOnly( sal_Bool bReadOnly = sal_True );
186 0 : 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 : virtual void SetSelection( const Selection& rSelection );
198 : virtual const Selection& GetSelection() const;
199 :
200 : virtual void ReplaceSelected( const XubString& rStr );
201 : virtual void DeleteSelected();
202 : virtual XubString GetSelected() const;
203 :
204 : virtual void Cut();
205 : virtual void Copy();
206 : virtual void Paste();
207 : void Undo();
208 :
209 : virtual void SetText( const XubString& rStr );
210 : virtual void SetText( const XubString& rStr, const Selection& rNewSelection );
211 : virtual XubString GetText() const;
212 :
213 : virtual void SetPlaceholderText( const OUString& rStr );
214 : virtual OUString GetPlaceholderText() const;
215 :
216 0 : void SaveValue() { maSaveValue = GetText(); }
217 0 : const XubString& GetSavedValue() const { return maSaveValue; }
218 :
219 0 : virtual void SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; }
220 0 : virtual const Link& GetModifyHdl() const { return maModifyHdl; }
221 0 : virtual void SetUpdateDataHdl( const Link& rLink ) { maUpdateDataHdl = rLink; }
222 0 : virtual const Link& GetUpdateDataHdl() const { return maUpdateDataHdl; }
223 :
224 : void SetSubEdit( Edit* pEdit );
225 0 : Edit* GetSubEdit() const { return mpSubEdit; }
226 :
227 : void SetAutocompleteHdl( const Link& rHdl );
228 0 : const Link& GetAutocompleteHdl() const { return maAutocompleteHdl; }
229 0 : AutocompleteAction GetAutocompleteAction() const { return meAutocompleteAction; }
230 :
231 : virtual Size CalcMinimumSize() const;
232 : virtual Size CalcMinimumSizeForText(const rtl::OUString &rString) const;
233 : virtual Size GetOptimalSize(WindowSizeType eType) const;
234 : virtual Size CalcSize( sal_uInt16 nChars ) const;
235 : virtual xub_StrLen GetMaxVisChars() const;
236 :
237 : xub_StrLen GetCharPos( const Point& rWindowPos ) const;
238 :
239 : // shows a warning box saying "text too long, truncated"
240 : static void ShowTruncationWarning( Window* pParent );
241 :
242 : static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
243 : static FncGetSpecialChars GetGetSpecialCharsFunction();
244 :
245 : static PopupMenu* CreatePopupMenu();
246 : static void DeletePopupMenu( PopupMenu* pMenu );
247 :
248 : virtual rtl::OUString GetSurroundingText() const;
249 : virtual Selection GetSurroundingTextSelection() const;
250 : virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue);
251 :
252 : // returns the minimum size a bordered Edit should have given the current
253 : // global style settings (needed by sc's inputwin.cxx)
254 : static Size GetMinimumEditSize();
255 : };
256 :
257 0 : inline sal_uLong Edit::IsUpdateDataEnabled() const
258 : {
259 0 : if ( mpUpdateDataTimer )
260 0 : return mpUpdateDataTimer->GetTimeout();
261 : else
262 0 : return sal_False;
263 : }
264 :
265 : #endif // _SV_EDIT_HXX
266 :
267 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|