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