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