1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef DBAUI_TABLEEDITORCONTROL_HXX
28 #define DBAUI_TABLEEDITORCONTROL_HXX
29 
30 #ifndef DBAUI_TABLEDESIGNCONTROL_HXX
31 #include "TableDesignControl.hxx"
32 #endif
33 #ifndef DBAUI_TABLEDESIGNVIEW_HXX
34 #include "TableDesignView.hxx"
35 #endif
36 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX
37 #include "TableFieldDescWin.hxx"
38 #endif
39 #ifndef DBAUI_TABLEROW_HXX
40 #include "TableRow.hxx"
41 #endif
42 #ifndef DBAUI_ENUMTYPES_HXX
43 #include "QEnumTypes.hxx"
44 #endif
45 #ifndef DBAUI_TYPEINFO_HXX
46 #include "TypeInfo.hxx"
47 #endif
48 
49 class Edit;
50 class SfxUndoManager;
51 namespace dbaui
52 {
53 	class OSQLNameEdit;
54 
55 	class OTableEditorCtrl : public OTableRowView
56 	{
57 		enum ChildFocusState
58 		{
59             HELPTEXT,
60 			DESCRIPTION,
61 			NAME,
62 			ROW,
63 			NONE
64 		};
65 
66 		::std::vector< ::boost::shared_ptr<OTableRow> >	m_aUndoList;
67 		::std::vector< ::boost::shared_ptr<OTableRow> >*	m_pRowList;
68 
69 		OSQLNameEdit*				pNameCell;
70 		::svt::ListBoxControl*		pTypeCell;
71 		Edit*						pHelpTextCell;
72         Edit*						pDescrCell;
73 		OTableFieldDescWin*			pDescrWin;			// properties of one column
74 
75 		 ::boost::shared_ptr<OTableRow> pActRow;
76 
77 		sal_uLong						nIndexEvent;
78 		sal_uLong						nCutEvent;
79 		sal_uLong						nPasteEvent;
80 		sal_uLong						nDeleteEvent;
81 		sal_uLong						nInsNewRowsEvent;
82 		sal_uLong						nInvalidateTypeEvent;
83 		sal_uLong						nEntryNotFoundEvent;
84 		ChildFocusState				m_eChildFocus;
85 
86 		long nOldDataPos;
87 
88 		sal_Bool bSaveOnMove;
89 		sal_Bool bReadOnly;
90 		//------------------------------------------------------------------
91 		// Hilfsklasse
92 		class ClipboardInvalidator
93 		{
94 		private:
95 			AutoTimer	m_aInvalidateTimer;
96 			OTableEditorCtrl* m_pOwner;
97 
98 		public:
99 			ClipboardInvalidator(sal_uLong nTimeout,OTableEditorCtrl*);
100 			~ClipboardInvalidator();
101 
102 		protected:
103 			DECL_LINK(OnInvalidate, void*);
104 		};
105 		friend class OTableEditorCtrl::ClipboardInvalidator;
106 
107 		ClipboardInvalidator	m_aInvalidate;
108 
109 	protected:
110 		virtual void Command( const CommandEvent& rEvt );
111 		virtual sal_Bool SeekRow(long nRow);
112 		virtual void PaintCell(OutputDevice& rDev, const Rectangle& rRect,
113 							   sal_uInt16 nColumnId ) const;
114 
115 		virtual void CursorMoved();
116 		virtual RowStatus GetRowStatus(long nRow) const;
117 
118 		virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol);
119 		virtual void InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol);
120 
121 		virtual void CellModified();
122 		virtual sal_Bool SaveModified();	// wird aufgerufen vor einem Zellenwechsel
123 										// return sal_False, verhindert Zellenwechsel
124 		virtual void Undo();
125 		virtual void Redo();
126 		virtual String GetCellText(long nRow, sal_uInt16 nColId) const;
127 		virtual sal_uInt32 GetTotalCellWidth(long nRow, sal_uInt16 nColId);
128 
129 		virtual void CopyRows();
130 		virtual void InsertRows( long nRow );
131 		virtual void DeleteRows();
132 		virtual void InsertNewRows( long nRow );
133 
134 		virtual sal_Bool IsPrimaryKeyAllowed( long nRow );
135 		virtual sal_Bool IsInsertNewAllowed( long nRow );
136 		virtual sal_Bool IsDeleteAllowed( long nRow );
137 
138 		void		 ClearModified();
139 
140 		void		 SetPrimaryKey( sal_Bool bSet );
141 		sal_Bool		 IsPrimaryKey();
142 
143 		DECL_LINK(ControlPreNotifyHdl, NotifyEvent*);
144 
145 	public:
146 		//	TYPEINFO();
147 		OTableEditorCtrl(Window* pParentWin);
148 		virtual			~OTableEditorCtrl();
149 		virtual sal_Bool	CursorMoving(long nNewRow, sal_uInt16 nNewCol);
150 		virtual void	UpdateAll();
151 		SfxUndoManager& GetUndoManager() const;
152 
153 		void			SetDescrWin( OTableFieldDescWin* pWin ){ pDescrWin = pWin; if (pDescrWin && pActRow) pDescrWin->DisplayData(pActRow->GetActFieldDescr()); }
154 		sal_Bool			SaveCurRow();
155 		void			SwitchType( const TOTypeInfoSP& _pType );
156 
157 		void			DisplayData( long nRow, sal_Bool bGrabFocus = sal_True );
158 			// erzwingt das Anzeigen der genannten Zeile (selbst wenn es eigentlich schon die aktuelle ist)
159 
160         virtual void    SetCellData( long nRow, sal_uInt16 nColId, const TOTypeInfoSP& _pTypeInfo );
161         virtual void    SetCellData( long nRow, sal_uInt16 nColId, const ::com::sun::star::uno::Any& _rSaveData );
162         virtual ::com::sun::star::uno::Any  GetCellData( long nRow, sal_uInt16 nColId );
163         virtual void    SetControlText( long nRow, sal_uInt16 nColId, const String& rText );
164         virtual String  GetControlText( long nRow, sal_uInt16 nColId );
165 
166 		virtual OTableDesignView* GetView() const;
167 
168         ::std::vector< ::boost::shared_ptr<OTableRow> >* GetRowList(){ return m_pRowList; }
169 
170         ::boost::shared_ptr<OTableRow>         GetActRow(){ return pActRow; }
171         void            CellModified( long nRow, sal_uInt16 nColId );
172 		void			SetReadOnly( sal_Bool bRead=sal_True );
173 
174 		virtual void Init();
175 		virtual void DeactivateCell(sal_Bool bUpdate = sal_True);
176 
177 		sal_Bool IsCutAllowed( long nRow = -1 );
178 		sal_Bool IsCopyAllowed( long nRow = -1 );
179 		sal_Bool IsPasteAllowed( long nRow = -1 );
180 		sal_Bool IsReadOnly();
181         OFieldDescription* GetFieldDescr( long nRow );
182 
183 		// window overloads
184 		virtual long			PreNotify( NotifyEvent& rNEvt );
185 
186 		// IClipboardTest
187 		virtual sal_Bool isCutAllowed() { return IsCutAllowed(); }
188 		virtual sal_Bool isCopyAllowed() { return IsCopyAllowed(); }
189 		virtual sal_Bool isPasteAllowed() { return IsPasteAllowed(); }
190 		virtual sal_Bool hasChildPathFocus() { return HasChildPathFocus(); }
191 
192 		virtual void cut();
193 		virtual void copy();
194 		virtual void paste();
195 	private:
196 		DECL_LINK( StartIndexing, void* );
197 		DECL_LINK( DelayedCut, void* );
198 		DECL_LINK( DelayedPaste, void* );
199 		DECL_LINK( DelayedDelete, void* );
200 		DECL_LINK( DelayedInsNewRows, void* );
201 		DECL_LINK( InvalidateFieldType, void* );
202 		DECL_LINK( EntryNotFound, void* );
203 
204 		void InitCellController();
205 		sal_Int32 HasFieldName( const String& rFieldName );
206 		String GenerateName( const String& rName );
207 		sal_Bool SetDataPtr( long nRow );
208 
209 		sal_Bool SaveData(long nRow, sal_uInt16 nColumnId);
210 		/** AdjustFieldDescription set the needed values for the description
211 			@param	_pFieldDesc		the field description where to set the values
212 			@param	_rMultiSel		contains the postions which changed for undo/redo
213 			@param	_nPos			the current position
214 			@param	_bSet			should a key be set
215 			@param	_bPrimaryKey	which value should the pkey have
216 		*/
217 		void AdjustFieldDescription( OFieldDescription* _pFieldDesc,
218 									 MultiSelection& _rMultiSel,
219 									 sal_Int32 _nPos,
220 									 sal_Bool _bSet,
221 									 sal_Bool _bPrimaryKey);
222 		/** InvalidateFeatures invalidates the slots SID_UNDO | SID_REDO | SID_SAVEDOC
223 		*/
224 		void InvalidateFeatures();
225 
226         void resetType();
227 	};
228 }
229 #endif // DBAUI_TABLEEDITORCONTROL_HXX
230 
231 
232 
233