xref: /AOO41X/main/svx/inc/svx/fmgridcl.hxx (revision 3334a7e6acdae9820fa1a6f556bb10129a8de6b2)
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 _SVX_FMGRIDCL_HXX
24 #define _SVX_FMGRIDCL_HXX
25 
26 #include <com/sun/star/container/XIndexContainer.hpp>
27 #include <com/sun/star/container/XNameContainer.hpp>
28 
29 #include <svx/gridctrl.hxx>
30 #include <svtools/transfer.hxx>
31 #include "svx/svxdllapi.h"
32 
33 //==================================================================
34 // FmGridHeader
35 //==================================================================
36 struct FmGridHeaderData;
37 class SVX_DLLPUBLIC FmGridHeader
38             :public ::svt::EditBrowserHeader
39             ,public DropTargetHelper
40 {
41 protected:
42     FmGridHeaderData*       m_pImpl;
43 
44     // trigger context menu execution
45     void    triggerColumnContextMenu( const ::Point& _rPreferredPos );
46 
47 public:
48     FmGridHeader( BrowseBox* pParent, WinBits nWinBits = WB_STDHEADERBAR | WB_DRAG );
49     ~FmGridHeader();
50 
51 public:
AccessControlFmGridHeader::AccessControl52     struct AccessControl { friend class FmGridControl; private: AccessControl() { } };
53 
triggerColumnContextMenu(const::Point & _rPreferredPos,const AccessControl &)54     inline  void    triggerColumnContextMenu( const ::Point& _rPreferredPos, const AccessControl& )
55     {
56         triggerColumnContextMenu( _rPreferredPos );
57     }
58 
59 protected:
60     virtual void Command( const CommandEvent& rCEvt );
61     virtual void RequestHelp( const HelpEvent& rHEvt );
62     virtual void Select();
63 
64     /** the value returned by GetItemPos is meaningless for the grid model if there are hidden columns,
65         so use GetModelColumnPos instead
66     */
67     sal_uInt16 GetModelColumnPos(sal_uInt16 nId) const;
68 
69     /** This is called before executing a context menu for a column. rMenu contains the initial entries
70         handled by this base class' method (which always has to be called).
71         Derived classes may alter the menu in any way and handle any additional entries in
72         PostExecuteColumnContextMenu.
73         All disabled entries will be removed before executing the menu, so be careful with separators
74         near entries you probably wish to disable ...
75     */
76     virtual void    PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu);
77     /** After executing the context menu for a column this method is called.
78     */
79     virtual void    PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult);
80 
81     // DropTargetHelper
82     virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt );
83     virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt );
84 
85     /** selects the column at the selection supplier.
86         @param  nColumnId
87             The column id.
88     */
89     void notifyColumnSelect(sal_uInt16 nColumnId);
90 private:
91     DECL_LINK( OnAsyncExecuteDrop, void* );
92 };
93 
94 //==================================================================
95 // FmGridControl
96 //==================================================================
97 class FmXGridPeer;
98 class SVX_DLLPUBLIC FmGridControl : public DbGridControl
99 
100 {
101     friend class FmGridHeader;
102     friend class FmXGridPeer;
103 
104     FmXGridPeer*        m_pPeer;
105     sal_Int32           m_nCurrentSelectedColumn;   // this is the column model (not the view) posisition ...
106     sal_uInt16          m_nMarkedColumnId;
107     sal_Bool            m_bSelecting;
108     sal_Bool            m_bInColumnMove : 1;
109 
110 public:
111     FmGridControl(
112         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >,
113         Window* pParent,
114         FmXGridPeer* _pPeer,
115         WinBits nBits);
116 
117     // Window
118     virtual void KeyInput( const KeyEvent& rKEvt );
119 
120     // ::com::sun::star::beans::XPropertyChangeListener
121     void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt);
122 
123     // ::com::sun::star::form::XPositioningListener
124     void positioned(const ::com::sun::star::lang::EventObject& rEvent);
125 
126     // XBound
127     sal_Bool commit();
128 
129     // ::com::sun::star::form::XInsertListener
130     void inserted(const ::com::sun::star::lang::EventObject& rEvent);
131 
132     // ::com::sun::star::form::XRestoreListener
133     void restored(const ::com::sun::star::lang::EventObject& rEvent);
134 
135     void markColumn(sal_uInt16 nId);
136     sal_Bool isColumnMarked(sal_uInt16 nId) const;
137 
138     sal_Int32   GetSelectedColumn() const;
139 
140     /** return the name of the specified object.
141         @param  eObjType
142             The type to ask for
143         @param  _nPosition
144             The position of a tablecell (index position), header bar  colum/row cell
145         @return
146             The name of the specified object.
147     */
148     virtual ::rtl::OUString GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const;
149 
150     /** return the description of the specified object.
151         @param  eObjType
152             The type to ask for
153         @param  _nPosition
154             The position of a tablecell (index position), header bar  colum/row cell
155         @return
156             The description of the specified object.
157     */
158     virtual ::rtl::OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const;
159 
160 protected:
161     virtual void Command(const CommandEvent& rEvt);
162 
163     virtual BrowserHeader* imp_CreateHeaderBar(BrowseBox* pParent);
164     virtual long QueryMinimumRowHeight();
165     virtual void RowHeightChanged();
166     virtual void ColumnResized(sal_uInt16 nId);
167     virtual void ColumnMoved(sal_uInt16 nId);
168     virtual void DeleteSelectedRows();
169     virtual void SetDesignMode(sal_Bool bMode);
170     virtual void CellModified();
171     virtual void HideColumn(sal_uInt16 nId);
172     virtual void ShowColumn(sal_uInt16 nId);
173 
IsInColumnMove() const174     sal_Bool    IsInColumnMove() const {return m_bInColumnMove;}
175 
176     virtual void BeginCursorAction();
177     virtual void EndCursorAction();
178     virtual void Select();
179 
180     // Initialisieren der Spalten
181     // a.) nur ueber Spaltenbeschreibung
182     virtual void InitColumnsByModels(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& xColumns);
183     // b.) im alivemode ueber Datenbankfelder
184     virtual void InitColumnsByFields(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& xFields);
185 
186             // some kind of impl version (for one single column) of our version of InitColumnsByFields
187             void InitColumnByField(
188                     DbGridColumn* _pColumn,
189                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumnModel,
190                     const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxFieldsByNames,
191                     const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxFieldsByIndex
192                 );
193 
GetPeer() const194     FmXGridPeer* GetPeer() const {return m_pPeer;}
195 
196     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>
197             getSelectionBookmarks();
198     sal_Bool selectBookmarks(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& _rBookmarks);
199 
200     /** returns if a column is selected
201         @param  nColumnId
202             The column id.
203         @param  _pColumn
204             The column to compare with.
205         @return
206             <TRUE/> if the column is selected, otherwise <FALSE/>
207     */
208     sal_Bool isColumnSelected(sal_uInt16 nColumnId,DbGridColumn* _pColumn);
209 };
210 
211 #endif // _SVX_FMGRIDCL_HXX
212 
213