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 INCLUDED_VCL_EDIT_HXX
21 : #define INCLUDED_VCL_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 SAL_MAX_INT32
47 : #define EDIT_UPDATEDATA_TIMEOUT 350
48 :
49 : typedef OUString (*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 : sal_Int32 mnMaxTextLen;
73 : sal_Int32 mnWidthInChars;
74 : sal_Int32 mnMaxWidthChars;
75 : AutocompleteAction meAutocompleteAction;
76 : sal_Unicode mcEchoChar;
77 : 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 : css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > mxISC;
90 :
91 : DECL_DLLPRIVATE_LINK( ImplUpdateDataHdl, void* );
92 :
93 : SAL_DLLPRIVATE bool ImplTruncateToMaxLen( OUString&, sal_Int32 nSelectionLen ) const;
94 : SAL_DLLPRIVATE void ImplInitEditData();
95 : SAL_DLLPRIVATE void ImplModified();
96 : SAL_DLLPRIVATE OUString ImplGetText() const;
97 : SAL_DLLPRIVATE void ImplRepaint(bool bLayout = false);
98 : SAL_DLLPRIVATE void ImplInvalidateOrRepaint();
99 : SAL_DLLPRIVATE void ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
100 : SAL_DLLPRIVATE void ImplSetText( const OUString& rStr, const Selection* pNewSelection = 0 );
101 : SAL_DLLPRIVATE void ImplInsertText( const OUString& rStr, const Selection* pNewSelection = 0, bool bIsUserInput = false );
102 : SAL_DLLPRIVATE OUString ImplGetValidString( const OUString& rString ) const;
103 : SAL_DLLPRIVATE void ImplClearBackground( long nXStart, long nXEnd );
104 : SAL_DLLPRIVATE void ImplPaintBorder( long nXStart, long nXEnd );
105 : SAL_DLLPRIVATE void ImplShowCursor( bool bOnlyIfVisible = true );
106 : SAL_DLLPRIVATE void ImplAlign();
107 : SAL_DLLPRIVATE void ImplAlignAndPaint();
108 : SAL_DLLPRIVATE sal_Int32 ImplGetCharPos( const Point& rWindowPos ) const;
109 : SAL_DLLPRIVATE void ImplSetCursorPos( sal_Int32 nChar, bool bSelect );
110 : SAL_DLLPRIVATE void ImplShowDDCursor();
111 : SAL_DLLPRIVATE void ImplHideDDCursor();
112 : SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKEvt );
113 : SAL_DLLPRIVATE void ImplCopyToSelectionClipboard();
114 : SAL_DLLPRIVATE void ImplCopy( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
115 : SAL_DLLPRIVATE void ImplPaste( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >& rxClipboard );
116 : SAL_DLLPRIVATE long ImplGetTextYPosition() const;
117 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker();
118 : SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > ImplGetBreakIterator() const;
119 :
120 : protected:
121 : using Control::ImplInitSettings;
122 : using Window::ImplInit;
123 : SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
124 : SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle );
125 : SAL_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
126 : SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId );
127 : SAL_DLLPRIVATE void ImplSetSelection( const Selection& rSelection, bool bPaint = true );
128 : SAL_DLLPRIVATE int ImplGetNativeControlType() const;
129 : SAL_DLLPRIVATE long ImplGetExtraOffset() const;
130 : static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( Window* pWin );
131 :
132 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
133 :
134 : // DragAndDropClient
135 : using vcl::unohelper::DragAndDropClient::dragEnter;
136 : using vcl::unohelper::DragAndDropClient::dragExit;
137 : using vcl::unohelper::DragAndDropClient::dragOver;
138 : virtual void dragGestureRecognized( const ::com::sun::star::datatransfer::dnd::DragGestureEvent& dge ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 : virtual void dragDropEnd( const ::com::sun::star::datatransfer::dnd::DragSourceDropEvent& dsde ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
140 : virtual void drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& dtde ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
141 : virtual void dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
142 : virtual void dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& dte ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 : virtual void dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 :
145 : protected:
146 : virtual void FillLayoutData() const SAL_OVERRIDE;
147 : Edit( WindowType nType );
148 :
149 : public:
150 : // public because needed in button.cxx
151 : SAL_DLLPRIVATE bool ImplUseNativeBorder( WinBits nStyle );
152 :
153 : Edit( Window* pParent, WinBits nStyle = WB_BORDER );
154 : Edit( Window* pParent, const ResId& rResId );
155 : virtual ~Edit();
156 :
157 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
158 : virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
159 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
160 : virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
161 : virtual void Resize() SAL_OVERRIDE;
162 : virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) SAL_OVERRIDE;
163 : virtual void GetFocus() SAL_OVERRIDE;
164 : virtual void LoseFocus() SAL_OVERRIDE;
165 : virtual void Tracking( const TrackingEvent& rTEvt ) SAL_OVERRIDE;
166 : virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
167 : virtual void StateChanged( StateChangedType nType ) SAL_OVERRIDE;
168 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
169 : virtual Window* GetPreferredKeyInputWindow() SAL_OVERRIDE;
170 :
171 : virtual void Modify();
172 : virtual void UpdateData();
173 :
174 : static bool IsCharInput( const KeyEvent& rKEvt );
175 :
176 : virtual void SetModifyFlag();
177 : virtual void ClearModifyFlag();
178 0 : virtual bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
179 :
180 : virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
181 0 : virtual void DisableUpdateData() { delete mpUpdateDataTimer; mpUpdateDataTimer = NULL; }
182 :
183 : void SetEchoChar( sal_Unicode c );
184 0 : sal_Unicode GetEchoChar() const { return mcEchoChar; }
185 :
186 : virtual void SetReadOnly( bool bReadOnly = true );
187 0 : virtual bool IsReadOnly() const { return mbReadOnly; }
188 :
189 : void SetInsertMode( bool bInsert );
190 : bool IsInsertMode() const;
191 :
192 : virtual void SetMaxTextLen( sal_Int32 nMaxLen = EDIT_NOLIMIT );
193 0 : virtual sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
194 :
195 : void SetWidthInChars(sal_Int32 nWidthInChars);
196 : sal_Int32 GetWidthInChars() const { return mnWidthInChars; }
197 :
198 : void setMaxWidthChars(sal_Int32 nWidth);
199 :
200 : virtual void SetSelection( const Selection& rSelection );
201 : virtual const Selection& GetSelection() const;
202 :
203 : virtual void ReplaceSelected( const OUString& rStr );
204 : virtual void DeleteSelected();
205 : virtual OUString GetSelected() const;
206 :
207 : virtual void Cut();
208 : virtual void Copy();
209 : virtual void Paste();
210 : void Undo();
211 :
212 : virtual void SetText( const OUString& rStr ) SAL_OVERRIDE;
213 : virtual void SetText( const OUString& rStr, const Selection& rNewSelection );
214 : virtual OUString GetText() const SAL_OVERRIDE;
215 :
216 : virtual void SetPlaceholderText( const OUString& rStr );
217 : virtual OUString GetPlaceholderText() const;
218 :
219 0 : void SaveValue() { maSaveValue = GetText(); }
220 0 : const OUString& GetSavedValue() const { return maSaveValue; }
221 :
222 0 : virtual void SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; }
223 0 : virtual const Link& GetModifyHdl() const { return maModifyHdl; }
224 0 : virtual void SetUpdateDataHdl( const Link& rLink ) { maUpdateDataHdl = rLink; }
225 :
226 : void SetSubEdit( Edit* pEdit );
227 0 : Edit* GetSubEdit() const { return mpSubEdit; }
228 :
229 : void SetAutocompleteHdl( const Link& rHdl );
230 0 : const Link& GetAutocompleteHdl() const { return maAutocompleteHdl; }
231 0 : AutocompleteAction GetAutocompleteAction() const { return meAutocompleteAction; }
232 :
233 : virtual Size CalcMinimumSize() const;
234 : virtual Size CalcMinimumSizeForText(const OUString &rString) const;
235 : virtual Size GetOptimalSize() const SAL_OVERRIDE;
236 : virtual Size CalcSize(sal_Int32 nChars) const;
237 : virtual sal_Int32 GetMaxVisChars() const;
238 :
239 : sal_Int32 GetCharPos( const Point& rWindowPos ) const;
240 :
241 : // shows a warning box saying "text too long, truncated"
242 : static void ShowTruncationWarning( Window* pParent );
243 :
244 : static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
245 : static FncGetSpecialChars GetGetSpecialCharsFunction();
246 :
247 : static PopupMenu* CreatePopupMenu();
248 : static void DeletePopupMenu( PopupMenu* pMenu );
249 :
250 : virtual OUString GetSurroundingText() const SAL_OVERRIDE;
251 : virtual Selection GetSurroundingTextSelection() const SAL_OVERRIDE;
252 : virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
253 :
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();
257 : };
258 :
259 : #endif // INCLUDED_VCL_EDIT_HXX
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|