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