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