Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / vcl / edit.hxx
blobe0d968950b6c3614fde2759f777de14165ff9d35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <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>
31 namespace com {
32 namespace sun {
33 namespace star {
34 namespace i18n {
35 class XBreakIterator;
36 class XExtendedInputSequenceChecker;
37 }}}}
39 struct DDInfo;
40 struct Impl_IMEInfos;
43 // - Edit-Types -
46 #define EDIT_NOLIMIT SAL_MAX_INT32
47 #define EDIT_UPDATEDATA_TIMEOUT 350
49 typedef OUString (*FncGetSpecialChars)( Window* pWin, const Font& rFont );
52 // - Edit -
55 enum AutocompleteAction{ AUTOCOMPLETE_KEYINPUT, AUTOCOMPLETE_TABFORWARD, AUTOCOMPLETE_TABBACKWARD };
57 class VCL_DLLPUBLIC Edit : public Control, public vcl::unohelper::DragAndDropClient
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;
89 css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > mxISC;
91 DECL_DLLPRIVATE_LINK( ImplUpdateDataHdl, void* );
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;
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 );
132 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener > mxDnDListener;
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;
145 protected:
146 virtual void FillLayoutData() const SAL_OVERRIDE;
147 Edit( WindowType nType );
149 public:
150 // public because needed in button.cxx
151 SAL_DLLPRIVATE bool ImplUseNativeBorder( WinBits nStyle );
153 Edit( Window* pParent, WinBits nStyle = WB_BORDER );
154 Edit( Window* pParent, const ResId& rResId );
155 virtual ~Edit();
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;
171 virtual void Modify();
172 virtual void UpdateData();
174 static bool IsCharInput( const KeyEvent& rKEvt );
176 virtual void SetModifyFlag();
177 virtual void ClearModifyFlag();
178 virtual bool IsModified() const { return mpSubEdit ? mpSubEdit->mbModified : mbModified; }
180 virtual void EnableUpdateData( sal_uLong nTimeout = EDIT_UPDATEDATA_TIMEOUT );
181 virtual void DisableUpdateData() { delete mpUpdateDataTimer; mpUpdateDataTimer = NULL; }
183 void SetEchoChar( sal_Unicode c );
184 sal_Unicode GetEchoChar() const { return mcEchoChar; }
186 virtual void SetReadOnly( bool bReadOnly = true );
187 virtual bool IsReadOnly() const { return mbReadOnly; }
189 void SetInsertMode( bool bInsert );
190 bool IsInsertMode() const;
192 virtual void SetMaxTextLen( sal_Int32 nMaxLen = EDIT_NOLIMIT );
193 virtual sal_Int32 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;
207 virtual void Cut();
208 virtual void Copy();
209 virtual void Paste();
210 void Undo();
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;
216 virtual void SetPlaceholderText( const OUString& rStr );
217 virtual OUString GetPlaceholderText() const;
219 void SaveValue() { maSaveValue = GetText(); }
220 const OUString& GetSavedValue() const { return maSaveValue; }
221 bool IsValueChangedFromSaved() const { return maSaveValue != GetText(); }
223 virtual void SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; }
224 virtual const Link& GetModifyHdl() const { return maModifyHdl; }
225 virtual void SetUpdateDataHdl( const Link& rLink ) { maUpdateDataHdl = rLink; }
227 void SetSubEdit( Edit* pEdit );
228 Edit* GetSubEdit() const { return mpSubEdit; }
230 void SetAutocompleteHdl( const Link& rHdl );
231 const Link& GetAutocompleteHdl() const { return maAutocompleteHdl; }
232 AutocompleteAction GetAutocompleteAction() const { return meAutocompleteAction; }
234 virtual Size CalcMinimumSize() const;
235 virtual Size CalcMinimumSizeForText(const OUString &rString) const;
236 virtual Size GetOptimalSize() const SAL_OVERRIDE;
237 virtual Size CalcSize(sal_Int32 nChars) const;
238 virtual sal_Int32 GetMaxVisChars() const;
240 sal_Int32 GetCharPos( const Point& rWindowPos ) const;
242 // shows a warning box saying "text too long, truncated"
243 static void ShowTruncationWarning( Window* pParent );
245 static void SetGetSpecialCharsFunction( FncGetSpecialChars fn );
246 static FncGetSpecialChars GetGetSpecialCharsFunction();
248 static PopupMenu* CreatePopupMenu();
249 static void DeletePopupMenu( PopupMenu* pMenu );
251 virtual OUString GetSurroundingText() const SAL_OVERRIDE;
252 virtual Selection GetSurroundingTextSelection() const SAL_OVERRIDE;
253 virtual bool set_property(const OString &rKey, const OString &rValue) SAL_OVERRIDE;
255 // returns the minimum size a bordered Edit should have given the current
256 // global style settings (needed by sc's inputwin.cxx)
257 static Size GetMinimumEditSize();
260 #endif // INCLUDED_VCL_EDIT_HXX
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */