1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_DBACCESS_SOURCE_UI_TABLEDESIGN_TEDITCONTROL_HXX
#define INCLUDED_DBACCESS_SOURCE_UI_TABLEDESIGN_TEDITCONTROL_HXX

#include <TableDesignControl.hxx>
#include <TableDesignView.hxx>
#include "TableFieldDescWin.hxx"
#include <TableRow.hxx>
#include <QEnumTypes.hxx>
#include <TypeInfo.hxx>

class Edit;
class SfxUndoManager;
namespace dbaui
{
    class OSQLNameEdit;

    class OTableEditorCtrl : public OTableRowView
    {
        enum ChildFocusState
        {
            HELPTEXT,
            DESCRIPTION,
            NAME,
            ROW,
            NONE
        };

        std::vector< std::shared_ptr<OTableRow> >*    m_pRowList;

        VclPtr<OSQLNameEdit>               pNameCell;
        VclPtr< ::svt::ListBoxControl>      pTypeCell;
        VclPtr<Edit>                       pHelpTextCell;
        VclPtr<Edit>                       pDescrCell;
        VclPtr<OTableFieldDescWin>         pDescrWin;          // properties of one column

         std::shared_ptr<OTableRow> pActRow;

        ImplSVEvent *               nCutEvent;
        ImplSVEvent *               nPasteEvent;
        ImplSVEvent *               nDeleteEvent;
        ImplSVEvent *               nInsNewRowsEvent;
        ImplSVEvent *               nInvalidateTypeEvent;
        ChildFocusState             m_eChildFocus;

        long nOldDataPos;

        bool bReadOnly;

        // helper class
        class ClipboardInvalidator final
        {
        private:
            AutoTimer m_aInvalidateTimer;
            VclPtr<OTableEditorCtrl> m_pOwner;

        public:
            explicit ClipboardInvalidator(OTableEditorCtrl*);
            ~ClipboardInvalidator();
            void Stop();

        private:
            DECL_LINK(OnInvalidate, Timer*, void);
        };

        friend class OTableEditorCtrl::ClipboardInvalidator;

        ClipboardInvalidator m_aInvalidate;

    protected:
        virtual void Command( const CommandEvent& rEvt ) override;
        virtual bool SeekRow(long nRow) override;
        virtual void PaintCell(OutputDevice& rDev, const tools::Rectangle& rRect,
                               sal_uInt16 nColumnId ) const override;

        virtual void CursorMoved() override;
        virtual RowStatus GetRowStatus(long nRow) const override;

        virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol) override;
        virtual void InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol) override;

        virtual void CellModified() override;
        virtual bool SaveModified() override; // is called before changing a cell (false prevents change)

        virtual OUString GetCellText(long nRow, sal_uInt16 nColId) const override;
        virtual sal_uInt32 GetTotalCellWidth(long nRow, sal_uInt16 nColId) override;

        virtual void CopyRows() override;
        virtual void InsertRows( long nRow ) override;
        virtual void DeleteRows() override;
        virtual void InsertNewRows( long nRow ) override;

        virtual bool IsPrimaryKeyAllowed() override;
        virtual bool IsInsertNewAllowed( long nRow ) override;
        virtual bool IsDeleteAllowed() override;

        void ClearModified();

        void SetPrimaryKey( bool bSet );
        bool IsPrimaryKey();

    public:
        explicit OTableEditorCtrl(vcl::Window* pParentWin);
        virtual ~OTableEditorCtrl() override;
        virtual void dispose() override;
        virtual bool CursorMoving(long nNewRow, sal_uInt16 nNewCol) override;
        SfxUndoManager& GetUndoManager() const;

        void SetDescrWin( OTableFieldDescWin* pWin )
        {
            pDescrWin = pWin;
            if (pDescrWin && pActRow)
                pDescrWin->DisplayData(pActRow->GetActFieldDescr());
        }
        void SaveCurRow();
        void SwitchType( const TOTypeInfoSP& _pType );

        /// force displaying of the given row
        void DisplayData( long nRow );

        virtual void SetCellData( long nRow, sal_uInt16 nColId, const TOTypeInfoSP& _pTypeInfo ) override;
        virtual void SetCellData( long nRow, sal_uInt16 nColId, const css::uno::Any& _rSaveData ) override;
        virtual css::uno::Any  GetCellData( long nRow, sal_uInt16 nColId ) override;
        virtual void SetControlText( long nRow, sal_uInt16 nColId, const OUString& rText ) override;

        virtual OTableDesignView* GetView() const override;<--- GetView is a virtual function

        std::vector< std::shared_ptr<OTableRow> >* GetRowList(){ return m_pRowList; }

        const std::shared_ptr<OTableRow>& GetActRow() const { return pActRow; }
        void CellModified( long nRow, sal_uInt16 nColId );
        void SetReadOnly( bool bRead );

        virtual void Init() override;
        virtual void DeactivateCell(bool bUpdate = true) override;

        bool IsCutAllowed();
        bool IsCopyAllowed();
        bool IsPasteAllowed() const;
        bool IsReadOnly() const { return bReadOnly;}
        OFieldDescription* GetFieldDescr( long nRow );

        // Window overrides
        virtual bool PreNotify( NotifyEvent& rNEvt ) override;

        // IClipboardTest
        virtual bool isCutAllowed() override { return IsCutAllowed(); }
        virtual bool isCopyAllowed() override { return IsCopyAllowed(); }
        virtual bool isPasteAllowed() override { return IsPasteAllowed(); }

        virtual void cut() override;
        virtual void copy() override;
        virtual void paste() override;

    private:
        DECL_LINK( DelayedCut, void*, void );
        DECL_LINK( DelayedPaste, void*, void );
        DECL_LINK( DelayedDelete, void*, void );
        DECL_LINK( DelayedInsNewRows, void*, void );
        DECL_LINK( InvalidateFieldType, void*, void );

        void InitCellController();
        sal_Int32 HasFieldName( const OUString& rFieldName );
        OUString GenerateName( const OUString& rName );
        bool SetDataPtr( long nRow );

        void SaveData(long nRow, sal_uInt16 nColumnId);
        /** AdjustFieldDescription set the needed values for the description
            @param  _pFieldDesc     the field description where to set the values
            @param  _rMultiSel      contains the positions which changed for undo/redo
            @param  _nPos           the current position
            @param  _bSet           should a key be set
            @param  _bPrimaryKey    which value should the pkey have
        */
        void AdjustFieldDescription( OFieldDescription* _pFieldDesc,
                                     MultiSelection& _rMultiSel,
                                     sal_Int32 _nPos,
                                     bool _bSet,
                                     bool _bPrimaryKey);
        /** InvalidateFeatures invalidates the slots SID_UNDO | SID_REDO | SID_SAVEDOC
        */
        void InvalidateFeatures();

        void resetType();
    };
}
#endif // INCLUDED_DBACCESS_SOURCE_UI_TABLEDESIGN_TEDITCONTROL_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */