1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/solar.h>
24 #include <tools/string.hxx>
25 #include <vcl/dllapi.h>
26 #include <vcl/timer.hxx>
27 #include <vcl/ctrl.hxx>
28 #include <vcl/menu.hxx>
29 #include <vcl/dndhelp.hxx>
30 #include <com/sun/star/uno/Reference.h>
37 class XExtendedInputSequenceChecker
;
47 #define EDIT_NOLIMIT STRING_LEN
48 #define EDIT_UPDATEDATA_TIMEOUT 350
50 typedef OUString (*FncGetSpecialChars
)( Window
* pWin
, const Font
& rFont
);
56 enum AutocompleteAction
{ AUTOCOMPLETE_KEYINPUT
, AUTOCOMPLETE_TABFORWARD
, AUTOCOMPLETE_TABBACKWARD
};
58 class VCL_DLLPUBLIC Edit
: public Control
, public vcl::unohelper::DragAndDropClient
62 Timer
* mpUpdateDataTimer
;
64 Impl_IMEInfos
* mpIMEInfos
;
65 OUStringBuffer maText
;
66 OUString maPlaceholderText
;
71 Selection maSelection
;
73 xub_StrLen mnMaxTextLen
;
74 sal_Int32 mnWidthInChars
;
75 sal_Int32 mnMaxWidthChars
;
76 AutocompleteAction meAutocompleteAction
;
77 sal_Unicode mcEchoChar
;
78 sal_Bool mbModified
:1,
82 mbClickedInSelection
:1,
88 Link maAutocompleteHdl
;
90 DECL_DLLPRIVATE_LINK( ImplUpdateDataHdl
, void* );
92 SAL_DLLPRIVATE
bool ImplTruncateToMaxLen( OUString
&, sal_uInt32 nSelectionLen
) const;
93 SAL_DLLPRIVATE
void ImplInitEditData();
94 SAL_DLLPRIVATE
void ImplModified();
95 SAL_DLLPRIVATE OUString
ImplGetText() const;
96 SAL_DLLPRIVATE
void ImplRepaint( sal_Int32 nStart
= 0, sal_Int32 nEnd
= STRING_LEN
, bool bLayout
= false );
97 SAL_DLLPRIVATE
void ImplInvalidateOrRepaint( sal_Int32 nStart
= 0, sal_Int32 nEnd
= STRING_LEN
);
98 SAL_DLLPRIVATE
void ImplDelete( const Selection
& rSelection
, sal_uInt8 nDirection
, sal_uInt8 nMode
);
99 SAL_DLLPRIVATE
void ImplSetText( const OUString
& rStr
, const Selection
* pNewSelection
= 0 );
100 SAL_DLLPRIVATE
void ImplInsertText( const OUString
& rStr
, const Selection
* pNewSelection
= 0, sal_Bool bIsUserInput
= sal_False
);
101 SAL_DLLPRIVATE OUString
ImplGetValidString( const OUString
& rString
) const;
102 SAL_DLLPRIVATE
void ImplClearBackground( long nXStart
, long nXEnd
);
103 SAL_DLLPRIVATE
void ImplPaintBorder( long nXStart
, long nXEnd
);
104 SAL_DLLPRIVATE
void ImplShowCursor( sal_Bool bOnlyIfVisible
= sal_True
);
105 SAL_DLLPRIVATE
void ImplAlign();
106 SAL_DLLPRIVATE
void ImplAlignAndPaint();
107 SAL_DLLPRIVATE sal_Int32
ImplGetCharPos( const Point
& rWindowPos
) const;
108 SAL_DLLPRIVATE
void ImplSetCursorPos( sal_Int32 nChar
, sal_Bool bSelect
);
109 SAL_DLLPRIVATE
void ImplShowDDCursor();
110 SAL_DLLPRIVATE
void ImplHideDDCursor();
111 SAL_DLLPRIVATE sal_Bool
ImplHandleKeyEvent( const KeyEvent
& rKEvt
);
112 SAL_DLLPRIVATE
void ImplCopyToSelectionClipboard();
113 SAL_DLLPRIVATE
void ImplCopy( ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboard
>& rxClipboard
);
114 SAL_DLLPRIVATE
void ImplPaste( ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::clipboard::XClipboard
>& rxClipboard
);
115 SAL_DLLPRIVATE
long ImplGetTextYPosition() const;
116 SAL_DLLPRIVATE ::com::sun::star::uno::Reference
< ::com::sun::star::i18n::XExtendedInputSequenceChecker
> ImplGetInputSequenceChecker() const;
117 SAL_DLLPRIVATE ::com::sun::star::uno::Reference
< ::com::sun::star::i18n::XBreakIterator
> ImplGetBreakIterator() const;
120 using Control::ImplInitSettings
;
121 using Window::ImplInit
;
122 SAL_DLLPRIVATE
void ImplInit( Window
* pParent
, WinBits nStyle
);
123 SAL_DLLPRIVATE WinBits
ImplInitStyle( WinBits nStyle
);
124 SAL_DLLPRIVATE
void ImplInitSettings( sal_Bool bFont
, sal_Bool bForeground
, sal_Bool bBackground
);
125 SAL_DLLPRIVATE
void ImplLoadRes( const ResId
& rResId
);
126 SAL_DLLPRIVATE
void ImplSetSelection( const Selection
& rSelection
, sal_Bool bPaint
= sal_True
);
127 SAL_DLLPRIVATE
int ImplGetNativeControlType() const;
128 SAL_DLLPRIVATE
long ImplGetExtraOffset() const;
129 static SAL_DLLPRIVATE
void ImplInvalidateOutermostBorder( Window
* pWin
);
131 ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::dnd::XDragSourceListener
> mxDnDListener
;
134 using vcl::unohelper::DragAndDropClient::dragEnter
;
135 using vcl::unohelper::DragAndDropClient::dragExit
;
136 using vcl::unohelper::DragAndDropClient::dragOver
;
137 virtual void dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent
& dge
) throw (::com::sun::star::uno::RuntimeException
);
138 virtual void dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent
& dsde
) throw (::com::sun::star::uno::RuntimeException
);
139 virtual void drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent
& dtde
) throw (::com::sun::star::uno::RuntimeException
);
140 virtual void dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent
& dtdee
) throw (::com::sun::star::uno::RuntimeException
);
141 virtual void dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent
& dte
) throw (::com::sun::star::uno::RuntimeException
);
142 virtual void dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent
& dtde
) throw (::com::sun::star::uno::RuntimeException
);
145 virtual void FillLayoutData() const;
146 Edit( WindowType nType
);
149 // public because needed in button.cxx
150 SAL_DLLPRIVATE
bool ImplUseNativeBorder( WinBits nStyle
);
152 Edit( Window
* pParent
, WinBits nStyle
= WB_BORDER
);
153 Edit( Window
* pParent
, const ResId
& rResId
);
156 virtual void MouseButtonDown( const MouseEvent
& rMEvt
);
157 virtual void MouseButtonUp( const MouseEvent
& rMEvt
);
158 virtual void KeyInput( const KeyEvent
& rKEvt
);
159 virtual void Paint( const Rectangle
& rRect
);
160 virtual void Resize();
161 virtual void Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
, sal_uLong nFlags
);
162 virtual void GetFocus();
163 virtual void LoseFocus();
164 virtual void Tracking( const TrackingEvent
& rTEvt
);
165 virtual void Command( const CommandEvent
& rCEvt
);
166 virtual void StateChanged( StateChangedType nType
);
167 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
168 virtual Window
* GetPreferredKeyInputWindow();
170 virtual void Modify();
171 virtual void UpdateData();
173 static sal_Bool
IsCharInput( const KeyEvent
& rKEvt
);
175 virtual void SetModifyFlag();
176 virtual void ClearModifyFlag();
177 virtual sal_Bool
IsModified() const { return mpSubEdit
? mpSubEdit
->mbModified
: mbModified
; }
179 virtual void EnableUpdateData( sal_uLong nTimeout
= EDIT_UPDATEDATA_TIMEOUT
);
180 virtual void DisableUpdateData() { delete mpUpdateDataTimer
; mpUpdateDataTimer
= NULL
; }
181 virtual sal_uLong
IsUpdateDataEnabled() const;
183 void SetEchoChar( sal_Unicode c
);
184 sal_Unicode
GetEchoChar() const { return mcEchoChar
; }
186 virtual void SetReadOnly( sal_Bool bReadOnly
= sal_True
);
187 virtual sal_Bool
IsReadOnly() const { return mbReadOnly
; }
189 void SetInsertMode( sal_Bool bInsert
);
190 sal_Bool
IsInsertMode() const;
192 virtual void SetMaxTextLen( xub_StrLen nMaxLen
= EDIT_NOLIMIT
);
193 virtual xub_StrLen
GetMaxTextLen() const { return mnMaxTextLen
; }
195 void SetWidthInChars(sal_Int32 nWidthInChars
);
196 sal_Int32
GetWidthInChars() const { return mnWidthInChars
; }
198 void setMaxWidthChars(sal_Int32 nWidth
);
200 virtual void SetSelection( const Selection
& rSelection
);
201 virtual const Selection
& GetSelection() const;
203 virtual void ReplaceSelected( const OUString
& rStr
);
204 virtual void DeleteSelected();
205 virtual OUString
GetSelected() const;
209 virtual void Paste();
212 virtual void SetText( const OUString
& rStr
);
213 virtual void SetText( const OUString
& rStr
, const Selection
& rNewSelection
);
214 virtual OUString
GetText() const;
216 virtual void SetPlaceholderText( const OUString
& rStr
);
217 virtual OUString
GetPlaceholderText() const;
219 void SaveValue() { maSaveValue
= GetText(); }
220 const OUString
& GetSavedValue() const { return maSaveValue
; }
222 virtual void SetModifyHdl( const Link
& rLink
) { maModifyHdl
= rLink
; }
223 virtual const Link
& GetModifyHdl() const { return maModifyHdl
; }
224 virtual void SetUpdateDataHdl( const Link
& rLink
) { maUpdateDataHdl
= rLink
; }
226 void SetSubEdit( Edit
* pEdit
);
227 Edit
* GetSubEdit() const { return mpSubEdit
; }
229 void SetAutocompleteHdl( const Link
& rHdl
);
230 const Link
& GetAutocompleteHdl() const { return maAutocompleteHdl
; }
231 AutocompleteAction
GetAutocompleteAction() const { return meAutocompleteAction
; }
233 virtual Size
CalcMinimumSize() const;
234 virtual Size
CalcMinimumSizeForText(const OUString
&rString
) const;
235 virtual Size
GetOptimalSize() const;
236 virtual Size
CalcSize( sal_uInt16 nChars
) const;
237 virtual xub_StrLen
GetMaxVisChars() const;
239 xub_StrLen
GetCharPos( const Point
& rWindowPos
) const;
241 // shows a warning box saying "text too long, truncated"
242 static void ShowTruncationWarning( Window
* pParent
);
244 static void SetGetSpecialCharsFunction( FncGetSpecialChars fn
);
245 static FncGetSpecialChars
GetGetSpecialCharsFunction();
247 static PopupMenu
* CreatePopupMenu();
248 static void DeletePopupMenu( PopupMenu
* pMenu
);
250 virtual OUString
GetSurroundingText() const;
251 virtual Selection
GetSurroundingTextSelection() const;
252 virtual bool set_property(const OString
&rKey
, const OString
&rValue
);
254 // returns the minimum size a bordered Edit should have given the current
255 // global style settings (needed by sc's inputwin.cxx)
256 static Size
GetMinimumEditSize();
259 inline sal_uLong
Edit::IsUpdateDataEnabled() const
261 if ( mpUpdateDataTimer
)
262 return mpUpdateDataTimer
->GetTimeout();
267 #endif // INCLUDED_VCL_EDIT_HXX
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */