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 #ifndef _SBA_GRID_HXX 23 #define _SBA_GRID_HXX 24 25 //#include <sdb/tools.hxx> 26 27 #ifndef _SVX_FMGRIDCL_HXX 28 #include <svx/fmgridcl.hxx> 29 #endif 30 31 #ifndef _SVX_FMGRIDIF_HXX 32 #include <svx/fmgridif.hxx> 33 #endif 34 35 #ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_ 36 #include <com/sun/star/sdb/XSQLQueryComposer.hpp> 37 #endif 38 #ifndef _COM_SUN_STAR_FRAME_XDISPATCH_HPP_ 39 #include <com/sun/star/frame/XDispatch.hpp> 40 #endif 41 #ifndef _COM_SUN_STAR_UTIL_URL_HPP_ 42 #include <com/sun/star/util/URL.hpp> 43 #endif 44 #ifndef _COMPHELPER_UNO3_HXX_ 45 #include <comphelper/uno3.hxx> 46 #endif 47 #ifndef _COMPHELPER_STLTYPES_HXX_ 48 #include <comphelper/stl_types.hxx> 49 #endif 50 #ifndef _SBA_MULTIPLEX_HXX 51 #include "sbamultiplex.hxx" 52 #endif 53 #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_ 54 #include <svx/dataaccessdescriptor.hxx> 55 #endif 56 #include <queue> 57 58 class SvNumberFormatter; 59 60 namespace dbaui 61 { 62 //------------------------------------------------------------------ 63 struct SbaURLCompare : public ::std::binary_function< ::com::sun::star::util::URL, ::com::sun::star::util::URL, bool> 64 { 65 bool operator() (const ::com::sun::star::util::URL& x, const ::com::sun::star::util::URL& y) const {return x.Complete == y.Complete ? true : false;} 66 }; 67 68 struct SbaURLHash 69 { 70 sal_Int32 operator() (const ::com::sun::star::util::URL& x) const {return x.Complete.hashCode();} 71 }; 72 //================================================================== 73 // SbaXGridControl 74 //================================================================== 75 76 // class ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > ; 77 FORWARD_DECLARE_INTERFACE(lang,XMultiServiceFactory) 78 79 class SbaXStatusMultiplexer; 80 class SbaXGridControl 81 :public FmXGridControl 82 ,public ::com::sun::star::frame::XDispatch 83 { 84 DECLARE_STL_MAP(::com::sun::star::util::URL, SbaXStatusMultiplexer*, SbaURLCompare,StatusMultiplexerArray); 85 StatusMultiplexerArray m_aStatusMultiplexer; 86 87 public: 88 SbaXGridControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 89 virtual ~SbaXGridControl(); 90 91 // UNO 92 DECLARE_UNO3_DEFAULTS(SbaXGridControl, FmXGridControl); 93 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException); 94 95 // XTypeProvider 96 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); 97 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException); 98 99 // ::com::sun::star::lang::XServiceInfo 100 ::rtl::OUString SAL_CALL getImplementationName() throw(); 101 virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(); 102 // need by registration 103 static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException ); 104 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException ); 105 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 106 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 107 108 // ::com::sun::star::frame::XDispatch 109 virtual void SAL_CALL dispatch(const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs) throw( ::com::sun::star::uno::RuntimeException ); 110 virtual void SAL_CALL addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException ); 111 virtual void SAL_CALL removeStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException ); 112 113 // ::com::sun::star::lang::XComponent 114 virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException ); 115 116 virtual void SAL_CALL createPeer(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > & rToolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > & rParentPeer) throw( ::com::sun::star::uno::RuntimeException ); 117 118 protected: 119 virtual FmXGridPeer* imp_CreatePeer(Window* pParent); 120 }; 121 122 //================================================================== 123 // SbaXGridPeer 124 //================================================================== 125 126 class SbaXGridPeer 127 :public FmXGridPeer 128 ,public ::com::sun::star::frame::XDispatch 129 { 130 ::cppu::OMultiTypeInterfaceContainerHelperVar< ::com::sun::star::util::URL,SbaURLHash , SbaURLCompare> m_aStatusListeners; 131 132 public: 133 SbaXGridPeer(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 134 virtual ~SbaXGridPeer(); 135 136 // UNO 137 virtual void SAL_CALL acquire() throw() { FmXGridPeer::acquire(); } 138 virtual void SAL_CALL release() throw() { FmXGridPeer::release(); } 139 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException); 140 141 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); 142 143 static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId(); 144 sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 > & rId ) throw (::com::sun::star::uno::RuntimeException); 145 static SbaXGridPeer* getImplementation(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rxIFace); 146 147 // ::com::sun::star::frame::XDispatch 148 virtual void SAL_CALL dispatch(const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs) throw( ::com::sun::star::uno::RuntimeException ); 149 virtual void SAL_CALL addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException ); 150 virtual void SAL_CALL removeStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException ); 151 152 // ::com::sun::star::frame::XDispatchProvider 153 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( ::com::sun::star::uno::RuntimeException ); 154 155 // ::com::sun::star::lang::XComponent 156 virtual void SAL_CALL dispose(void) throw( ::com::sun::star::uno::RuntimeException ); 157 158 protected: 159 virtual FmGridControl* imp_CreateControl(Window* pParent, WinBits nStyle); 160 #if defined(_MSC_VER) && (_MSC_VER >= 1310 ) 161 typedef ::com::sun::star::frame::XStatusListener xstlist_type; 162 typedef ::com::sun::star::uno::Reference< xstlist_type > xlistener_type; 163 void NotifyStatusChanged(const ::com::sun::star::util::URL& aUrl, const xlistener_type & xControl = xlistener_type() ); 164 #else 165 void NotifyStatusChanged(const ::com::sun::star::util::URL& aUrl, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > ()); 166 #endif // # _MSC_VER>=1310 167 168 private: 169 // for any execution of XDispatch::dispatch 170 struct DispatchArgs 171 { 172 ::com::sun::star::util::URL aURL; 173 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs; 174 }; 175 ::std::queue< DispatchArgs > m_aDispatchArgs; 176 DECL_LINK( OnDispatchEvent, void* ); 177 178 // for dynamic states of our 4 dispatchable URLs 179 enum DispatchType 180 { 181 dtBrowserAttribs, 182 dtRowHeight, 183 dtColumnAttribs, 184 dtColumnWidth, 185 186 dtUnknown 187 }; 188 DispatchType classifyDispatchURL( const ::com::sun::star::util::URL& _rURL ); 189 190 DECLARE_STL_STDKEY_MAP( DispatchType, sal_Bool, MapDispatchToBool ); 191 MapDispatchToBool m_aDispatchStates; 192 }; 193 194 //================================================================== 195 // SbaGridHeader 196 //================================================================== 197 198 class SbaGridHeader 199 :public FmGridHeader 200 ,public DragSourceHelper 201 { 202 public: 203 SbaGridHeader(BrowseBox* pParent, WinBits nWinBits = WB_STDHEADERBAR | WB_DRAG); 204 205 protected: 206 207 // FmGridHeader overridables 208 virtual void PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu); 209 virtual void PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult); 210 211 private: 212 // DragSourceHelper overridables 213 virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel ); 214 215 // Window overridables 216 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 217 218 sal_Bool ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos); 219 220 private: 221 using FmGridHeader::StartDrag; 222 }; 223 224 // ========================================================================= 225 // interfaces for communication between the vcl grid control and a controller 226 // ------------------------------------------------------------------------- 227 class SbaGridListener 228 { 229 public: 230 virtual void RowChanged() = 0; 231 virtual void ColumnChanged() = 0; 232 virtual void SelectionChanged() = 0; 233 virtual void CellActivated() = 0; 234 virtual void CellDeactivated() = 0; 235 virtual void BeforeDrop() = 0; 236 virtual void AfterDrop() = 0; 237 }; 238 239 //================================================================== 240 // SbaGridControl 241 //================================================================== 242 //------------------------------------------------------------------ 243 class UnoDataBrowserController; 244 class SbaGridControl : public FmGridControl 245 { 246 friend class SbaGridHeader; 247 friend class SbaXGridPeer; 248 249 // Attributes 250 protected: 251 ::svx::ODataAccessDescriptor m_aDataDescriptor; 252 SbaGridListener* m_pMasterListener; 253 254 sal_Int32 m_nAsyncDropEvent; 255 256 sal_uInt16 m_nCurrentActionColId; 257 // UI actions (e.g. a context menu) may be performed on columns which aren't the current one 258 // and aren't selected, so we have to track this column id 259 260 sal_Bool m_bActivatingForDrop; 261 // Attribute Access 262 public: 263 sal_uInt16 GetCurrentActionColumn() const { return m_nCurrentActionColId; } 264 265 public: 266 SbaGridControl(::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >,Window* pParent, FmXGridPeer* _pPeer, WinBits nBits = WB_TABSTOP); 267 virtual ~SbaGridControl(); 268 269 virtual void Command( const CommandEvent& rCEvt ); 270 virtual void Select(); 271 272 void SetMasterListener(SbaGridListener* pListener) { m_pMasterListener = pListener; } 273 274 virtual void ActivateCell(long nRow, sal_uInt16 nCol, sal_Bool bSetCellFocus = sal_True); 275 virtual void DeactivateCell(sal_Bool bUpdate = sal_True); 276 void ActivateCell() { FmGridControl::ActivateCell(); } 277 278 sal_Bool IsAllSelected() const { return (GetSelectRowCount() == GetRowCount()) && (GetRowCount() > 0); } 279 280 HeaderBar* GetHeaderBar() const { return FmGridControl::GetHeaderBar(); } 281 282 /** return the description of the specified object. 283 @param eObjType 284 The type to ask for 285 @param _nPosition 286 The position of a tablecell (index position), header bar column/row cell 287 @return 288 The description of the specified object. 289 */ 290 virtual ::rtl::OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const; 291 292 virtual void DeleteSelectedRows(); 293 /** copies the currently selected rows to the clipboard 294 @precond 295 at least one row is selected 296 */ 297 void CopySelectedRowsToClipboard(); 298 299 300 protected: 301 // DragSourceHelper overridables 302 virtual void StartDrag( sal_Int8 _nAction, const Point& _rPosPixel ); 303 304 // BrowseBox overridables 305 virtual void CursorMoved(); 306 virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt ); 307 virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt ); 308 virtual void MouseButtonDown( const BrowserMouseEvent& rMEvt); 309 310 // EditBrowseBox overridables 311 virtual BrowserHeader* imp_CreateHeaderBar(BrowseBox* pParent); 312 virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol); 313 314 // DbGridControl overridables 315 virtual void PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu); 316 virtual void PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult); 317 318 // DbGridControl overridables 319 virtual void onRowChange(); 320 virtual void onColumnChange(); 321 322 // my own overridables 323 virtual void BeforeDrop(); 324 virtual void AfterDrop(); 325 326 // get a fields property set from a model pos 327 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getField(sal_uInt16 nModelPos); 328 329 // get my data source 330 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getDataSource() const; 331 332 // drag events 333 virtual void DoColumnDrag(sal_uInt16 nColumnPos); 334 virtual void DoRowDrag(sal_Int16 nRowPos); 335 virtual void DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos); 336 337 void SetBrowserAttrs(); 338 void SetColWidth(sal_uInt16 nColId); 339 void SetRowHeight(); 340 void SetColAttrs(sal_uInt16 nColId); 341 342 SvNumberFormatter* GetDatasourceFormatter(); 343 344 DECL_LINK(AsynchDropEvent, void*); 345 346 private: 347 sal_Bool IsReadOnlyDB() const; 348 void implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag ); 349 350 private: 351 using FmGridControl::AcceptDrop; 352 using FmGridControl::ExecuteDrop; 353 using FmGridControl::MouseButtonDown; 354 }; 355 } 356 #endif // _SBA_GRID_HXX 357 358 /* vim: set noet sw=4 ts=4: */ 359