1*0d63794cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*0d63794cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*0d63794cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*0d63794cSAndrew Rist * distributed with this work for additional information
6*0d63794cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*0d63794cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*0d63794cSAndrew Rist * "License"); you may not use this file except in compliance
9*0d63794cSAndrew Rist * with the License. You may obtain a copy of the License at
10*0d63794cSAndrew Rist *
11*0d63794cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*0d63794cSAndrew Rist *
13*0d63794cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*0d63794cSAndrew Rist * software distributed under the License is distributed on an
15*0d63794cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0d63794cSAndrew Rist * KIND, either express or implied. See the License for the
17*0d63794cSAndrew Rist * specific language governing permissions and limitations
18*0d63794cSAndrew Rist * under the License.
19*0d63794cSAndrew Rist *
20*0d63794cSAndrew Rist *************************************************************/
21*0d63794cSAndrew Rist
22*0d63794cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef _SV_EDIT_HXX
25cdf0e10cSrcweir #define _SV_EDIT_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vcl/sv.h>
28cdf0e10cSrcweir #include <vcl/dllapi.h>
29cdf0e10cSrcweir #include <vcl/timer.hxx>
30cdf0e10cSrcweir #include <vcl/ctrl.hxx>
31cdf0e10cSrcweir #include <vcl/menu.hxx>
32cdf0e10cSrcweir #include <vcl/dndhelp.hxx>
33cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
34cdf0e10cSrcweir
35cdf0e10cSrcweir namespace com {
36cdf0e10cSrcweir namespace sun {
37cdf0e10cSrcweir namespace star {
38cdf0e10cSrcweir namespace i18n {
39cdf0e10cSrcweir class XBreakIterator;
40cdf0e10cSrcweir class XExtendedInputSequenceChecker;
41cdf0e10cSrcweir }}}}
42cdf0e10cSrcweir
43cdf0e10cSrcweir class ImplSubEdit;
44cdf0e10cSrcweir struct DDInfo;
45cdf0e10cSrcweir struct Impl_IMEInfos;
46cdf0e10cSrcweir
47cdf0e10cSrcweir // --------------
48cdf0e10cSrcweir // - Edit-Types -
49cdf0e10cSrcweir // --------------
50cdf0e10cSrcweir
51cdf0e10cSrcweir #define EDIT_NOLIMIT STRING_LEN
52cdf0e10cSrcweir #define EDIT_UPDATEDATA_TIMEOUT 350
53cdf0e10cSrcweir
54cdf0e10cSrcweir typedef XubString (*FncGetSpecialChars)( Window* pWin, const Font& rFont );
55cdf0e10cSrcweir
56cdf0e10cSrcweir // --------
57cdf0e10cSrcweir // - Edit -
58cdf0e10cSrcweir // --------
59cdf0e10cSrcweir
60cdf0e10cSrcweir enum AutocompleteAction{ AUTOCOMPLETE_KEYINPUT, AUTOCOMPLETE_TABFORWARD, AUTOCOMPLETE_TABBACKWARD };
61cdf0e10cSrcweir
62cdf0e10cSrcweir class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
63cdf0e10cSrcweir {
64cdf0e10cSrcweir private:
65cdf0e10cSrcweir Edit* mpSubEdit;
66cdf0e10cSrcweir Timer* mpUpdateDataTimer;
67cdf0e10cSrcweir DDInfo* mpDDInfo;
68cdf0e10cSrcweir Impl_IMEInfos* mpIMEInfos;
69cdf0e10cSrcweir XubString maText;
70cdf0e10cSrcweir XubString maSaveValue;
71cdf0e10cSrcweir XubString maUndoText;
72cdf0e10cSrcweir XubString maRedoText;
73cdf0e10cSrcweir long mnXOffset;
74cdf0e10cSrcweir Selection maSelection;
75cdf0e10cSrcweir sal_uInt16 mnAlign;
76cdf0e10cSrcweir xub_StrLen mnMaxTextLen;
77cdf0e10cSrcweir AutocompleteAction meAutocompleteAction;
78cdf0e10cSrcweir xub_Unicode mcEchoChar;
79cdf0e10cSrcweir sal_Bool mbModified:1,
80cdf0e10cSrcweir mbInternModified:1,
81cdf0e10cSrcweir mbReadOnly:1,
82cdf0e10cSrcweir mbInsertMode:1,
83cdf0e10cSrcweir mbClickedInSelection:1,
84cdf0e10cSrcweir mbIsSubEdit:1,
85cdf0e10cSrcweir mbInMBDown:1,
86cdf0e10cSrcweir mbActivePopup:1;
87cdf0e10cSrcweir Link maModifyHdl;
88cdf0e10cSrcweir Link maUpdateDataHdl;
89cdf0e10cSrcweir Link maAutocompleteHdl;
90cdf0e10cSrcweir
91cdf0e10cSrcweir DECL_DLLPRIVATE_LINK( ImplUpdateDataHdl, Timer* );
92cdf0e10cSrcweir
93cdf0e10cSrcweir SAL_DLLPRIVATE bool ImplTruncateToMaxLen( rtl::OUString&, sal_uInt32 nSelectionLen ) const;
94cdf0e10cSrcweir SAL_DLLPRIVATE void ImplInitEditData();
95cdf0e10cSrcweir SAL_DLLPRIVATE void ImplModified();
96cdf0e10cSrcweir SAL_DLLPRIVATE XubString ImplGetText() const;
97cdf0e10cSrcweir SAL_DLLPRIVATE void ImplRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN, bool bLayout = false );
98cdf0e10cSrcweir SAL_DLLPRIVATE void ImplInvalidateOrRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN );
99cdf0e10cSrcweir SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
100cdf0e10cSrcweir SAL_DLLPRIVATE void ImplSetText( const XubString& rStr, const Selection* pNewSelection = 0 );
101cdf0e10cSrcweir SAL_DLLPRIVATE void ImplInsertText( const XubString& rStr, const Selection* pNewSelection = 0, sal_Bool bIsUserInput = sal_False );
102cdf0e10cSrcweir SAL_DLLPRIVATE String ImplGetValidString( const String& rString ) const;
103cdf0e10cSrcweir SAL_DLLPRIVATE void ImplClearBackground( long nXStart, long nXEnd );
104cdf0e10cSrcweir SAL_DLLPRIVATE void ImplShowCursor( sal_Bool bOnlyIfVisible = sal_True );
105cdf0e10cSrcweir SAL_DLLPRIVATE void ImplAlign();
106cdf0e10cSrcweir SAL_DLLPRIVATE void ImplAlignAndPaint();
107cdf0e10cSrcweir SAL_DLLPRIVATE xub_StrLen ImplGetCharPos( const Point& rWindowPos ) const;
108cdf0e10cSrcweir SAL_DLLPRIVATE void ImplSetCursorPos( xub_StrLen nChar, sal_Bool bSelect );
109cdf0e10cSrcweir SAL_DLLPRIVATE void ImplShowDDCursor();
110cdf0e10cSrcweir SAL_DLLPRIVATE void ImplHideDDCursor();
111cdf0e10cSrcweir SAL_DLLPRIVATE sal_Bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
112cdf0e10cSrcweir SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
113cdf0e10cSrcweir SAL_DLLPRIVATE void ImplCopy( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
114cdf0e10cSrcweir SAL_DLLPRIVATE void ImplPaste( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
115cdf0e10cSrcweir SAL_DLLPRIVATE long ImplGetExtraOffset() const;
116cdf0e10cSrcweir SAL_DLLPRIVATE long ImplGetTextYPosition() const;
117cdf0e10cSrcweir SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker() const;
118cdf0e10cSrcweir SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > ImplGetBreakIterator() const;
119cdf0e10cSrcweir
120cdf0e10cSrcweir protected:
121cdf0e10cSrcweir using Control::ImplInitSettings;
122cdf0e10cSrcweir using Window::ImplInit;
123cdf0e10cSrcweir SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
124cdf0e10cSrcweir SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
125cdf0e10cSrcweir SAL_DLLPRIVATE void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
126cdf0e10cSrcweir SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
127cdf0e10cSrcweir SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, sal_Bool bPaint = sal_True );
128cdf0e10cSrcweir SAL_DLLPRIVATE int ImplGetNativeControlType();
129cdf0e10cSrcweir static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( Window* pWin );
130cdf0e10cSrcweir
131cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
132cdf0e10cSrcweir
133cdf0e10cSrcweir // DragAndDropClient
134cdf0e10cSrcweir using vcl::unohelper::DragAndDropClient::dragEnter;
135cdf0e10cSrcweir using vcl::unohelper::DragAndDropClient::dragExit;
136cdf0e10cSrcweir using vcl::unohelper::DragAndDropClient::dragOver;
137cdf0e10cSrcweir virtual void dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent& dge ) throw (::com::sun::star::uno::RuntimeException);
138cdf0e10cSrcweir virtual void dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& dsde ) throw (::com::sun::star::uno::RuntimeException);
139cdf0e10cSrcweir virtual void drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
140cdf0e10cSrcweir virtual void dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) throw (::com::sun::star::uno::RuntimeException);
141cdf0e10cSrcweir virtual void dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& dte ) throw (::com::sun::star::uno::RuntimeException);
142cdf0e10cSrcweir virtual void dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde ) throw (::com::sun::star::uno::RuntimeException);
143cdf0e10cSrcweir
144cdf0e10cSrcweir protected:
145cdf0e10cSrcweir virtual void FillLayoutData() const;
146cdf0e10cSrcweir
147cdf0e10cSrcweir Edit( WindowType nType );
148cdf0e10cSrcweir
149cdf0e10cSrcweir public:
150cdf0e10cSrcweir // public because needed in button.cxx
151cdf0e10cSrcweir SAL_DLLPRIVATE bool ImplUseNativeBorder( WinBits nStyle );
152cdf0e10cSrcweir
153cdf0e10cSrcweir Edit( Window* pParent, WinBits nStyle = WB_BORDER );
154cdf0e10cSrcweir Edit( Window* pParent, const ResId& rResId );
155cdf0e10cSrcweir Edit( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabeledByRelation );
156cdf0e10cSrcweir virtual ~Edit();
157cdf0e10cSrcweir
158cdf0e10cSrcweir virtual void MouseButtonDown( const MouseEvent& rMEvt );
159cdf0e10cSrcweir virtual void MouseButtonUp( const MouseEvent& rMEvt );
160cdf0e10cSrcweir virtual void KeyInput( const KeyEvent& rKEvt );
161cdf0e10cSrcweir virtual void Paint( const Rectangle& rRect );
162cdf0e10cSrcweir virtual void Resize();
163cdf0e10cSrcweir virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
164cdf0e10cSrcweir virtual void GetFocus();
165cdf0e10cSrcweir virtual void LoseFocus();
166cdf0e10cSrcweir virtual void Tracking( const TrackingEvent& rTEvt );
167cdf0e10cSrcweir virtual void Command( const CommandEvent& rCEvt );
168cdf0e10cSrcweir virtual void StateChanged( StateChangedType nType );
169cdf0e10cSrcweir virtual void DataChanged( const DataChangedEvent& rDCEvt );
170cdf0e10cSrcweir virtual Window* GetPreferredKeyInputWindow();
171cdf0e10cSrcweir
172cdf0e10cSrcweir virtual void Modify();
173cdf0e10cSrcweir virtual void UpdateData();
174cdf0e10cSrcweir
175cdf0e10cSrcweir static sal_Bool IsCharInput( const KeyEvent& rKEvt );
176cdf0e10cSrcweir
177cdf0e10cSrcweir virtual void SetModifyFlag();
178cdf0e10cSrcweir virtual void ClearModifyFlag();
IsModified() const179cdf0e10cSrcweir virtual sal_Bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
180cdf0e10cSrcweir
181cdf0e10cSrcweir virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
DisableUpdateData()182cdf0e10cSrcweir virtual void DisableUpdateData() { delete mpUpdateDataTimer; mpUpdateDataTimer = NULL; }
183cdf0e10cSrcweir virtual sal_uLong IsUpdateDataEnabled() const;
184cdf0e10cSrcweir
185cdf0e10cSrcweir void SetEchoChar( xub_Unicode c );
GetEchoChar() const186cdf0e10cSrcweir xub_Unicode GetEchoChar() const { return mcEchoChar; }
187cdf0e10cSrcweir
188cdf0e10cSrcweir virtual void SetReadOnly( sal_Bool bReadOnly = sal_True );
IsReadOnly() const189cdf0e10cSrcweir virtual sal_Bool IsReadOnly() const { return mbReadOnly; }
190cdf0e10cSrcweir
191cdf0e10cSrcweir void SetInsertMode( sal_Bool bInsert );
192cdf0e10cSrcweir sal_Bool IsInsertMode() const;
193cdf0e10cSrcweir
194cdf0e10cSrcweir virtual void SetMaxTextLen( xub_StrLen nMaxLen = EDIT_NOLIMIT );
GetMaxTextLen() const195cdf0e10cSrcweir virtual xub_StrLen GetMaxTextLen() const { return mnMaxTextLen; }
196cdf0e10cSrcweir
197cdf0e10cSrcweir virtual void SetSelection( const Selection& rSelection );
198cdf0e10cSrcweir virtual const Selection& GetSelection() const;
199cdf0e10cSrcweir
200cdf0e10cSrcweir virtual void ReplaceSelected( const XubString& rStr );
201cdf0e10cSrcweir virtual void DeleteSelected();
202cdf0e10cSrcweir virtual XubString GetSelected() const;
203cdf0e10cSrcweir
204cdf0e10cSrcweir virtual void Cut();
205cdf0e10cSrcweir virtual void Copy();
206cdf0e10cSrcweir virtual void Paste();
207cdf0e10cSrcweir void Undo();
208cdf0e10cSrcweir
209cdf0e10cSrcweir virtual void SetText( const XubString& rStr );
210cdf0e10cSrcweir virtual void SetText( const XubString& rStr, const Selection& rNewSelection );
211cdf0e10cSrcweir virtual XubString GetText() const;
212cdf0e10cSrcweir
SaveValue()213cdf0e10cSrcweir void SaveValue() { maSaveValue = GetText(); }
GetSavedValue() const214cdf0e10cSrcweir const XubString& GetSavedValue() const { return maSaveValue; }
215cdf0e10cSrcweir
SetModifyHdl(const Link & rLink)216cdf0e10cSrcweir virtual void SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; }
GetModifyHdl() const217cdf0e10cSrcweir virtual const Link& GetModifyHdl() const { return maModifyHdl; }
SetUpdateDataHdl(const Link & rLink)218cdf0e10cSrcweir virtual void SetUpdateDataHdl( const Link& rLink ) { maUpdateDataHdl = rLink; }
GetUpdateDataHdl() const219cdf0e10cSrcweir virtual const Link& GetUpdateDataHdl() const { return maUpdateDataHdl; }
220cdf0e10cSrcweir
221cdf0e10cSrcweir void SetSubEdit( Edit* pEdit );
GetSubEdit() const222cdf0e10cSrcweir Edit* GetSubEdit() const { return mpSubEdit; }
223cdf0e10cSrcweir
224cdf0e10cSrcweir void SetAutocompleteHdl( const Link& rHdl );
GetAutocompleteHdl() const225cdf0e10cSrcweir const Link& GetAutocompleteHdl() const { return maAutocompleteHdl; }
GetAutocompleteAction() const226cdf0e10cSrcweir AutocompleteAction GetAutocompleteAction() const { return meAutocompleteAction; }
227cdf0e10cSrcweir
228cdf0e10cSrcweir virtual Size CalcMinimumSize() const;
229cdf0e10cSrcweir virtual Size GetOptimalSize(WindowSizeType eType) const;
230cdf0e10cSrcweir virtual Size CalcSize( sal_uInt16 nChars ) const;
231cdf0e10cSrcweir virtual xub_StrLen GetMaxVisChars() const;
232cdf0e10cSrcweir
233cdf0e10cSrcweir xub_StrLen GetCharPos( const Point& rWindowPos ) const;
234cdf0e10cSrcweir
235cdf0e10cSrcweir // shows a warning box saying "text too long, truncated"
236cdf0e10cSrcweir static void ShowTruncationWarning( Window* pParent );
237cdf0e10cSrcweir
238cdf0e10cSrcweir static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
239cdf0e10cSrcweir static FncGetSpecialChars GetGetSpecialCharsFunction();
240cdf0e10cSrcweir
241cdf0e10cSrcweir static PopupMenu* CreatePopupMenu();
242cdf0e10cSrcweir static void DeletePopupMenu( PopupMenu* pMenu );
243cdf0e10cSrcweir
244cdf0e10cSrcweir virtual XubString GetSurroundingText() const;
245cdf0e10cSrcweir virtual Selection GetSurroundingTextSelection() const;
246cdf0e10cSrcweir
247cdf0e10cSrcweir // returns the minimum size a bordered Edit should have given the current
248cdf0e10cSrcweir // global style settings (needed by sc's inputwin.cxx)
249cdf0e10cSrcweir static Size GetMinimumEditSize();
250cdf0e10cSrcweir };
251cdf0e10cSrcweir
IsUpdateDataEnabled() const252cdf0e10cSrcweir inline sal_uLong Edit::IsUpdateDataEnabled() const
253cdf0e10cSrcweir {
254cdf0e10cSrcweir if ( mpUpdateDataTimer )
255cdf0e10cSrcweir return mpUpdateDataTimer->GetTimeout();
256cdf0e10cSrcweir else
257cdf0e10cSrcweir return sal_False;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir #endif // _SV_EDIT_HXX
261