xref: /aoo41x/main/vcl/inc/vcl/edit.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SV_EDIT_HXX
29 #define _SV_EDIT_HXX
30 
31 #include <vcl/sv.h>
32 #include <vcl/dllapi.h>
33 #include <vcl/timer.hxx>
34 #include <vcl/ctrl.hxx>
35 #include <vcl/menu.hxx>
36 #include <vcl/dndhelp.hxx>
37 #include <com/sun/star/uno/Reference.h>
38 
39 namespace com {
40 namespace sun {
41 namespace star {
42 namespace i18n {
43 	class XBreakIterator;
44     class XExtendedInputSequenceChecker;
45 }}}}
46 
47 class ImplSubEdit;
48 struct DDInfo;
49 struct Impl_IMEInfos;
50 
51 // --------------
52 // - Edit-Types -
53 // --------------
54 
55 #define EDIT_NOLIMIT				STRING_LEN
56 #define EDIT_UPDATEDATA_TIMEOUT 	350
57 
58 typedef XubString (*FncGetSpecialChars)( Window* pWin, const Font& rFont );
59 
60 // --------
61 // - Edit -
62 // --------
63 
64 enum AutocompleteAction{ AUTOCOMPLETE_KEYINPUT, AUTOCOMPLETE_TABFORWARD, AUTOCOMPLETE_TABBACKWARD };
65 
66 class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
67 {
68 private:
69     Edit*               mpSubEdit;
70 	Timer*				mpUpdateDataTimer;
71 	DDInfo* 			mpDDInfo;
72 	Impl_IMEInfos*		mpIMEInfos;
73 	XubString			maText;
74 	XubString			maSaveValue;
75 	XubString			maUndoText;
76 	XubString			maRedoText;
77 	long				mnXOffset;
78 	Selection			maSelection;
79 	sal_uInt16				mnAlign;
80 	xub_StrLen			mnMaxTextLen;
81 	AutocompleteAction	meAutocompleteAction;
82 	xub_Unicode 		mcEchoChar;
83 	sal_Bool				mbModified:1,
84 						mbInternModified:1,
85 						mbReadOnly:1,
86 						mbInsertMode:1,
87 						mbClickedInSelection:1,
88 						mbIsSubEdit:1,
89 						mbInMBDown:1,
90 						mbActivePopup:1;
91 	Link				maModifyHdl;
92 	Link				maUpdateDataHdl;
93 	Link				maAutocompleteHdl;
94 
95 	DECL_DLLPRIVATE_LINK(      ImplUpdateDataHdl, Timer* );
96 
97     SAL_DLLPRIVATE bool        ImplTruncateToMaxLen( rtl::OUString&, sal_uInt32 nSelectionLen ) const;
98 	SAL_DLLPRIVATE void        ImplInitEditData();
99 	SAL_DLLPRIVATE void        ImplModified();
100 	SAL_DLLPRIVATE XubString   ImplGetText() const;
101 	SAL_DLLPRIVATE void        ImplRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN, bool bLayout = false );
102     SAL_DLLPRIVATE void        ImplInvalidateOrRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN );
103 	SAL_DLLPRIVATE void        ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
104 	SAL_DLLPRIVATE void        ImplSetText( const XubString& rStr, const Selection* pNewSelection = 0 );
105     SAL_DLLPRIVATE void        ImplInsertText( const XubString& rStr, const Selection* pNewSelection = 0, sal_Bool bIsUserInput = sal_False );
106     SAL_DLLPRIVATE String      ImplGetValidString( const String& rString ) const;
107 	SAL_DLLPRIVATE void        ImplClearBackground( long nXStart, long nXEnd );
108 	SAL_DLLPRIVATE void        ImplShowCursor( sal_Bool bOnlyIfVisible = sal_True );
109 	SAL_DLLPRIVATE void        ImplAlign();
110 	SAL_DLLPRIVATE void        ImplAlignAndPaint();
111 	SAL_DLLPRIVATE xub_StrLen  ImplGetCharPos( const Point& rWindowPos ) const;
112 	SAL_DLLPRIVATE void        ImplSetCursorPos( xub_StrLen nChar, sal_Bool bSelect );
113 	SAL_DLLPRIVATE void	       ImplShowDDCursor();
114 	SAL_DLLPRIVATE void        ImplHideDDCursor();
115 	SAL_DLLPRIVATE sal_Bool        ImplHandleKeyEvent( const KeyEvent& rKEvt );
116     SAL_DLLPRIVATE void        ImplCopyToSelectionClipboard();
117     SAL_DLLPRIVATE void        ImplCopy( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
118     SAL_DLLPRIVATE void        ImplPaste( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
119     SAL_DLLPRIVATE long        ImplGetExtraOffset() const;
120     SAL_DLLPRIVATE long        ImplGetTextYPosition() const;
121     SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker() const;
122     SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > ImplGetBreakIterator() const;
123 
124 protected:
125     using Control::ImplInitSettings;
126     using Window::ImplInit;
127 	SAL_DLLPRIVATE void        ImplInit( Window* pParent, WinBits nStyle );
128 	SAL_DLLPRIVATE WinBits     ImplInitStyle( WinBits nStyle );
129 	SAL_DLLPRIVATE void        ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
130 	SAL_DLLPRIVATE void        ImplLoadRes( const ResId& rResId );
131 	SAL_DLLPRIVATE void        ImplSetSelection( const Selection& rSelection, sal_Bool bPaint = sal_True );
132     SAL_DLLPRIVATE int         ImplGetNativeControlType();
133     static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( Window* pWin );
134 
135 	::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
136 
137     // DragAndDropClient
138     using vcl::unohelper::DragAndDropClient::dragEnter;
139     using vcl::unohelper::DragAndDropClient::dragExit;
140     using vcl::unohelper::DragAndDropClient::dragOver;
141     virtual void        dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent& dge ) throw (::com::sun::star::uno::RuntimeException);
142     virtual void        dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& dsde ) throw (::com::sun::star::uno::RuntimeException);
143     virtual void        drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
144     virtual void        dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) throw (::com::sun::star::uno::RuntimeException);
145     virtual void        dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& dte ) throw (::com::sun::star::uno::RuntimeException);
146     virtual void        dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
147 
148     protected:
149     virtual void FillLayoutData() const;
150 
151 						Edit( WindowType nType );
152 
153 public:
154     // public because needed in button.cxx
155     SAL_DLLPRIVATE bool        ImplUseNativeBorder( WinBits nStyle );
156 
157 						Edit( Window* pParent, WinBits nStyle = WB_BORDER );
158 						Edit( Window* pParent, const ResId& rResId );
159                         Edit( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabeledByRelation );
160 						virtual ~Edit();
161 
162 	virtual void		MouseButtonDown( const MouseEvent& rMEvt );
163 	virtual void		MouseButtonUp( const MouseEvent& rMEvt );
164 	virtual void		KeyInput( const KeyEvent& rKEvt );
165 	virtual void		Paint( const Rectangle& rRect );
166 	virtual void		Resize();
167 	virtual void		Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
168 	virtual void		GetFocus();
169 	virtual void		LoseFocus();
170 	virtual void		Tracking( const TrackingEvent& rTEvt );
171 	virtual void		Command( const CommandEvent& rCEvt );
172 	virtual void		StateChanged( StateChangedType nType );
173 	virtual void		DataChanged( const DataChangedEvent& rDCEvt );
174     virtual Window*     GetPreferredKeyInputWindow();
175 
176 	virtual void		Modify();
177 	virtual void		UpdateData();
178 
179 	static sal_Bool 		IsCharInput( const KeyEvent& rKEvt );
180 
181 	virtual void		SetModifyFlag();
182 	virtual void		ClearModifyFlag();
183 	virtual sal_Bool		IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
184 
185 	virtual void		EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
186 	virtual void		DisableUpdateData() { delete mpUpdateDataTimer; mpUpdateDataTimer = NULL; }
187 	virtual sal_uLong		IsUpdateDataEnabled() const;
188 
189 	void				SetEchoChar( xub_Unicode c );
190 	xub_Unicode 		GetEchoChar() const { return mcEchoChar; }
191 
192 	virtual void		SetReadOnly( sal_Bool bReadOnly = sal_True );
193 	virtual sal_Bool		IsReadOnly() const { return mbReadOnly; }
194 
195 	void				SetInsertMode( sal_Bool bInsert );
196 	sal_Bool				IsInsertMode() const;
197 
198 	virtual void		SetMaxTextLen( xub_StrLen nMaxLen = EDIT_NOLIMIT );
199 	virtual xub_StrLen	GetMaxTextLen() const { return mnMaxTextLen; }
200 
201     virtual void		SetSelection( const Selection& rSelection );
202 	virtual const Selection&	GetSelection() const;
203 
204 	virtual void		ReplaceSelected( const XubString& rStr );
205 	virtual void		DeleteSelected();
206 	virtual XubString	GetSelected() const;
207 
208 	virtual void		Cut();
209 	virtual void		Copy();
210 	virtual void		Paste();
211 	void				Undo();
212 
213 	virtual void		SetText( const XubString& rStr );
214 	virtual void		SetText( const XubString& rStr, const Selection& rNewSelection );
215 	virtual XubString	GetText() const;
216 
217 	void				SaveValue() { maSaveValue = GetText(); }
218 	const XubString&	GetSavedValue() const { return maSaveValue; }
219 
220 	virtual void		SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; }
221 	virtual const Link&	GetModifyHdl() const { return maModifyHdl; }
222 	virtual void		SetUpdateDataHdl( const Link& rLink ) { maUpdateDataHdl = rLink; }
223 	virtual const Link& GetUpdateDataHdl() const { return maUpdateDataHdl; }
224 
225 	void				SetSubEdit( Edit* pEdit );
226 	Edit*				GetSubEdit() const { return mpSubEdit; }
227 
228 	void				SetAutocompleteHdl( const Link& rHdl );
229 	const Link& 		GetAutocompleteHdl() const { return maAutocompleteHdl; }
230 	AutocompleteAction	GetAutocompleteAction() const { return meAutocompleteAction; }
231 
232 	virtual Size		CalcMinimumSize() 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 XubString GetSurroundingText() const;
249 	virtual Selection GetSurroundingTextSelection() const;
250 
251 	// returns the minimum size a bordered Edit should have given the current
252 	// global style settings (needed by sc's inputwin.cxx)
253 	static Size GetMinimumEditSize();
254 };
255 
256 inline sal_uLong Edit::IsUpdateDataEnabled() const
257 {
258 	if ( mpUpdateDataTimer )
259 		return mpUpdateDataTimer->GetTimeout();
260 	else
261 		return sal_False;
262 }
263 
264 #endif	// _SV_EDIT_HXX
265