xref: /AOO41X/main/vcl/inc/vcl/edit.hxx (revision 67e470dafe1997e73f56ff7ff4878983707e3e07)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_EDIT_HXX
25 #define _SV_EDIT_HXX
26 
27 #include <vcl/sv.h>
28 #include <vcl/dllapi.h>
29 #include <vcl/timer.hxx>
30 #include <vcl/ctrl.hxx>
31 #include <vcl/menu.hxx>
32 #include <vcl/dndhelp.hxx>
33 #include <com/sun/star/uno/Reference.h>
34 
35 namespace com {
36 namespace sun {
37 namespace star {
38 namespace i18n {
39     class XBreakIterator;
40     class XExtendedInputSequenceChecker;
41 }}}}
42 
43 class ImplSubEdit;
44 struct DDInfo;
45 struct Impl_IMEInfos;
46 
47 // --------------
48 // - Edit-Types -
49 // --------------
50 
51 #define EDIT_NOLIMIT                STRING_LEN
52 #define EDIT_UPDATEDATA_TIMEOUT     350
53 
54 typedef XubString (*FncGetSpecialChars)( Window* pWin, const Font& rFont );
55 
56 // --------
57 // - Edit -
58 // --------
59 
60 enum AutocompleteAction{ AUTOCOMPLETE_KEYINPUT, AUTOCOMPLETE_TABFORWARD, AUTOCOMPLETE_TABBACKWARD };
61 
62 class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
63 {
64 private:
65     Edit*               mpSubEdit;
66     Timer*              mpUpdateDataTimer;
67     DDInfo*             mpDDInfo;
68     Impl_IMEInfos*      mpIMEInfos;
69     XubString           maText;
70     XubString           maSaveValue;
71     XubString           maUndoText;
72     XubString           maRedoText;
73     long                mnXOffset;
74     Selection           maSelection;
75     sal_uInt16              mnAlign;
76     xub_StrLen          mnMaxTextLen;
77     AutocompleteAction  meAutocompleteAction;
78     xub_Unicode         mcEchoChar;
79     sal_Bool                mbModified:1,
80                         mbInternModified:1,
81                         mbReadOnly:1,
82                         mbInsertMode:1,
83                         mbClickedInSelection:1,
84                         mbIsSubEdit:1,
85                         mbInMBDown:1,
86                         mbActivePopup:1;
87     Link                maModifyHdl;
88     Link                maUpdateDataHdl;
89     Link                maAutocompleteHdl;
90 
91     DECL_DLLPRIVATE_LINK(      ImplUpdateDataHdl, Timer* );
92 
93     SAL_DLLPRIVATE bool        ImplTruncateToMaxLen( rtl::OUString&, sal_uInt32 nSelectionLen ) const;
94     SAL_DLLPRIVATE void        ImplInitEditData();
95     SAL_DLLPRIVATE void        ImplModified();
96     SAL_DLLPRIVATE XubString   ImplGetText() const;
97     SAL_DLLPRIVATE void        ImplRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN, bool bLayout = false );
98     SAL_DLLPRIVATE void        ImplInvalidateOrRepaint( xub_StrLen nStart = 0, xub_StrLen nEnd = STRING_LEN );
99     SAL_DLLPRIVATE void        ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uInt8 nMode );
100     SAL_DLLPRIVATE void        ImplSetText( const XubString& rStr, const Selection* pNewSelection = 0 );
101     SAL_DLLPRIVATE void        ImplInsertText( const XubString& rStr, const Selection* pNewSelection = 0, sal_Bool bIsUserInput = sal_False );
102     SAL_DLLPRIVATE String      ImplGetValidString( const String& rString ) const;
103     SAL_DLLPRIVATE void        ImplClearBackground( 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 xub_StrLen  ImplGetCharPos( const Point& rWindowPos ) const;
108     SAL_DLLPRIVATE void        ImplSetCursorPos( xub_StrLen 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        ImplGetExtraOffset() const;
116     SAL_DLLPRIVATE long        ImplGetTextYPosition() const;
117     SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > ImplGetInputSequenceChecker() const;
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( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
126     SAL_DLLPRIVATE void        ImplLoadRes( const ResId& rResId );
127     SAL_DLLPRIVATE void        ImplSetSelection( const Selection& rSelection, sal_Bool bPaint = sal_True );
128     SAL_DLLPRIVATE int         ImplGetNativeControlType();
129     static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder( Window* pWin );
130 
131     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
132 
133     // DragAndDropClient
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);
143 
144     protected:
145     virtual void FillLayoutData() const;
146 
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                         Edit( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabeledByRelation );
156                         virtual ~Edit();
157 
158     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
159     virtual void        MouseButtonUp( const MouseEvent& rMEvt );
160     virtual void        KeyInput( const KeyEvent& rKEvt );
161     virtual void        Paint( const Rectangle& rRect );
162     virtual void        Resize();
163     virtual void        Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags );
164     virtual void        GetFocus();
165     virtual void        LoseFocus();
166     virtual void        Tracking( const TrackingEvent& rTEvt );
167     virtual void        Command( const CommandEvent& rCEvt );
168     virtual void        StateChanged( StateChangedType nType );
169     virtual void        DataChanged( const DataChangedEvent& rDCEvt );
170     virtual Window*     GetPreferredKeyInputWindow();
171 
172     virtual void        Modify();
173     virtual void        UpdateData();
174 
175     static sal_Bool         IsCharInput( const KeyEvent& rKEvt );
176 
177     virtual void        SetModifyFlag();
178     virtual void        ClearModifyFlag();
IsModified() const179     virtual sal_Bool        IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
180 
181     virtual void        EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
DisableUpdateData()182     virtual void        DisableUpdateData() { delete mpUpdateDataTimer; mpUpdateDataTimer = NULL; }
183     virtual sal_uLong       IsUpdateDataEnabled() const;
184 
185     void                SetEchoChar( xub_Unicode c );
GetEchoChar() const186     xub_Unicode         GetEchoChar() const { return mcEchoChar; }
187 
188     virtual void        SetReadOnly( sal_Bool bReadOnly = sal_True );
IsReadOnly() const189     virtual sal_Bool        IsReadOnly() const { return mbReadOnly; }
190 
191     void                SetInsertMode( sal_Bool bInsert );
192     sal_Bool                IsInsertMode() const;
193 
194     virtual void        SetMaxTextLen( xub_StrLen nMaxLen = EDIT_NOLIMIT );
GetMaxTextLen() const195     virtual xub_StrLen  GetMaxTextLen() const { return mnMaxTextLen; }
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 
SaveValue()213     void                SaveValue() { maSaveValue = GetText(); }
GetSavedValue() const214     const XubString&    GetSavedValue() const { return maSaveValue; }
215 
SetModifyHdl(const Link & rLink)216     virtual void        SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; }
GetModifyHdl() const217     virtual const Link& GetModifyHdl() const { return maModifyHdl; }
SetUpdateDataHdl(const Link & rLink)218     virtual void        SetUpdateDataHdl( const Link& rLink ) { maUpdateDataHdl = rLink; }
GetUpdateDataHdl() const219     virtual const Link& GetUpdateDataHdl() const { return maUpdateDataHdl; }
220 
221     void                SetSubEdit( Edit* pEdit );
GetSubEdit() const222     Edit*               GetSubEdit() const { return mpSubEdit; }
223 
224     void                SetAutocompleteHdl( const Link& rHdl );
GetAutocompleteHdl() const225     const Link&         GetAutocompleteHdl() const { return maAutocompleteHdl; }
GetAutocompleteAction() const226     AutocompleteAction  GetAutocompleteAction() const { return meAutocompleteAction; }
227 
228     virtual Size        CalcMinimumSize() const;
229     virtual Size        GetOptimalSize(WindowSizeType eType) const;
230     virtual Size        CalcSize( sal_uInt16 nChars ) const;
231     virtual xub_StrLen  GetMaxVisChars() const;
232 
233     xub_StrLen          GetCharPos( const Point& rWindowPos ) const;
234 
235     // shows a warning box saying "text too long, truncated"
236     static void         ShowTruncationWarning( Window* pParent );
237 
238     static void                 SetGetSpecialCharsFunction( FncGetSpecialChars fn );
239     static FncGetSpecialChars   GetGetSpecialCharsFunction();
240 
241     static PopupMenu*   CreatePopupMenu();
242     static void         DeletePopupMenu( PopupMenu* pMenu );
243 
244     virtual XubString GetSurroundingText() const;
245     virtual Selection GetSurroundingTextSelection() const;
246 
247     // returns the minimum size a bordered Edit should have given the current
248     // global style settings (needed by sc's inputwin.cxx)
249     static Size GetMinimumEditSize();
250 };
251 
IsUpdateDataEnabled() const252 inline sal_uLong Edit::IsUpdateDataEnabled() const
253 {
254     if ( mpUpdateDataTimer )
255         return mpUpdateDataTimer->GetTimeout();
256     else
257         return sal_False;
258 }
259 
260 #endif  // _SV_EDIT_HXX
261