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 #ifndef _SVX_FILTNAV_HXX 28 #define _SVX_FILTNAV_HXX 29 30 #include <com/sun/star/form/XForm.hpp> 31 #include <com/sun/star/form/runtime/XFormController.hpp> 32 #include <com/sun/star/form/runtime/XFilterController.hpp> 33 #include <svl/lstner.hxx> 34 #include <svl/brdcst.hxx> 35 36 #include <vcl/window.hxx> 37 #include <sfx2/childwin.hxx> 38 #include <svl/poolitem.hxx> 39 #include <sfx2/bindings.hxx> 40 #include <sfx2/dockwin.hxx> 41 #include <sfx2/ctrlitem.hxx> 42 #include <vcl/image.hxx> 43 #include <svtools/svtreebx.hxx> 44 45 #include <vcl/dialog.hxx> 46 #include <vcl/group.hxx> 47 #include <vcl/dockwin.hxx> 48 #include "svx/fmtools.hxx" 49 #include "fmexch.hxx" 50 #include <connectivity/sqlparse.hxx> 51 #include "fmexch.hxx" 52 #include "sqlparserclient.hxx" 53 54 class FmFormShell; 55 56 //........................................................................ 57 namespace svxform 58 { 59 //........................................................................ 60 61 class FmFilterItem; 62 class FmFilterItems; 63 class FmParentData; 64 class FmFilterAdapter; 65 66 //======================================================================== 67 // data structure for the filter model 68 //======================================================================== 69 class FmFilterData 70 { 71 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xORB; 72 FmParentData* m_pParent; 73 ::rtl::OUString m_aText; 74 75 public: 76 TYPEINFO(); 77 FmFilterData(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmParentData* pParent = NULL, const ::rtl::OUString& rText = ::rtl::OUString()) 78 :m_xORB( _rxFactory ) 79 ,m_pParent( pParent ) 80 ,m_aText( rText ) 81 {} 82 virtual ~FmFilterData(){} 83 84 void SetText( const ::rtl::OUString& rText ){ m_aText = rText; } 85 ::rtl::OUString GetText() const { return m_aText; } 86 FmParentData* GetParent() const {return m_pParent;} 87 88 virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 89 }; 90 91 //======================================================================== 92 class FmParentData : public FmFilterData 93 { 94 protected: 95 ::std::vector< FmFilterData* > m_aChildren; 96 97 public: 98 TYPEINFO(); 99 FmParentData(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmParentData* pParent, const ::rtl::OUString& rText) 100 : FmFilterData(_rxFactory,pParent, rText) 101 {} 102 virtual ~FmParentData(); 103 104 ::std::vector< FmFilterData* >& GetChildren() { return m_aChildren; } 105 }; 106 107 //======================================================================== 108 // Item representing the forms and subforms 109 class FmFormItem : public FmParentData 110 { 111 ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > m_xController; 112 ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFilterController > m_xFilterController; 113 114 public: 115 TYPEINFO(); 116 117 FmFormItem( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmParentData* _pParent, 118 const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & _xController, 119 const ::rtl::OUString& _rText) 120 :FmParentData( _rxFactory, _pParent, _rText ) 121 ,m_xController( _xController ) 122 ,m_xFilterController( _xController, ::com::sun::star::uno::UNO_QUERY_THROW ) 123 { 124 } 125 126 inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& 127 GetController() { return m_xController; } 128 129 inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFilterController >& 130 GetFilterController() { return m_xFilterController; } 131 132 virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 133 }; 134 135 //======================================================================== 136 class FmFilterItems : public FmParentData 137 { 138 public: 139 TYPEINFO(); 140 FmFilterItems(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory):FmParentData(_rxFactory,NULL, ::rtl::OUString()){} 141 FmFilterItems(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,FmFormItem* pParent, const ::rtl::OUString& rText ):FmParentData(_rxFactory,pParent, rText){} 142 143 FmFilterItem* Find( const ::sal_Int32 _nFilterComponentIndex ) const; 144 virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 145 }; 146 147 //======================================================================== 148 class FmFilterItem : public FmFilterData 149 { 150 ::rtl::OUString m_aFieldName; 151 const sal_Int32 m_nComponentIndex; 152 153 public: 154 TYPEINFO(); 155 FmFilterItem( 156 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory, 157 FmFilterItems* pParent, 158 const ::rtl::OUString& aFieldName, 159 const ::rtl::OUString& aCondition, 160 const sal_Int32 _nComponentIndex 161 ); 162 163 const ::rtl::OUString& GetFieldName() const {return m_aFieldName;} 164 sal_Int32 GetComponentIndex() const { return m_nComponentIndex; } 165 166 virtual Image GetImage( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 167 }; 168 169 //======================================================================== 170 class FmFilterModel : public FmParentData 171 ,public SfxBroadcaster 172 ,public ::svxform::OSQLParserClient 173 { 174 friend class FmFilterAdapter; 175 176 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > m_xControllers; 177 ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > m_xController; 178 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xORB; 179 FmFilterAdapter* m_pAdapter; 180 FmFilterItems* m_pCurrentItems; 181 182 public: 183 TYPEINFO(); 184 FmFilterModel(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 185 virtual ~FmFilterModel(); 186 187 void Update(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers, const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xCurrent); 188 void Clear(); 189 sal_Bool ValidateText(FmFilterItem* pItem, UniString& rText, UniString& rErrorMsg) const; 190 void Append(FmFilterItems* pItems, FmFilterItem* pFilterItem); 191 void SetTextForItem(FmFilterItem* pItem, const ::rtl::OUString& rText); 192 193 FmFormItem* GetCurrentForm() const {return m_pCurrentItems ? (FmFormItem*)m_pCurrentItems->GetParent() : NULL;} 194 FmFilterItems* GetCurrentItems() const {return m_pCurrentItems;} 195 void SetCurrentItems(FmFilterItems* pCurrent); 196 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getORB() const { return m_xORB; } 197 198 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & GetControllers() const {return m_xControllers;} 199 const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & GetCurrentController() const {return m_xController;} 200 void SetCurrentController(const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xController); 201 202 void Remove(FmFilterData* pFilterItem); 203 void AppendFilterItems( FmFormItem& _rItem ); 204 void EnsureEmptyFilterRows( FmParentData& _rItem ); 205 206 protected: 207 void Insert(const ::std::vector<FmFilterData*>::iterator& rPos, FmFilterData* pFilterItem); 208 void Remove( const ::std::vector<FmFilterData*>::iterator& rPos ); 209 FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xController) const; 210 FmFormItem* Find(const ::std::vector<FmFilterData*>& rItems, const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& xForm) const; 211 void Update(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers, FmParentData* pParent); 212 }; 213 214 //======================================================================== 215 //======================================================================== 216 class OFilterItemExchange : public OLocalExchange 217 { 218 ::std::vector<FmFilterItem*> m_aDraggedEntries; 219 FmFormItem* m_pFormItem; // ensure that we drop on the same form 220 221 public: 222 OFilterItemExchange(); 223 224 static sal_uInt32 getFormatId( ); 225 inline static sal_Bool hasFormat( const DataFlavorExVector& _rFormats ); 226 227 const ::std::vector<FmFilterItem*>& getDraggedEntries() const { return m_aDraggedEntries; } 228 void setDraggedEntries(const ::std::vector<FmFilterItem*>& _rList) { m_aDraggedEntries = _rList; } 229 FmFormItem* getFormItem() const { return m_pFormItem; } 230 231 void setFormItem( FmFormItem* _pItem ) { m_pFormItem = _pItem; } 232 void addSelectedItem( FmFilterItem* _pItem) { m_aDraggedEntries.push_back(_pItem); } 233 234 protected: 235 virtual void AddSupportedFormats(); 236 }; 237 238 inline sal_Bool OFilterItemExchange::hasFormat( const DataFlavorExVector& _rFormats ) 239 { 240 return OLocalExchange::hasFormat( _rFormats, getFormatId() ); 241 } 242 243 //==================================================================== 244 //= OFilterExchangeHelper 245 //==================================================================== 246 class OFilterExchangeHelper : public OLocalExchangeHelper 247 { 248 public: 249 OFilterExchangeHelper(Window* _pDragSource) : OLocalExchangeHelper(_pDragSource) { } 250 251 OFilterItemExchange* operator->() const { return static_cast<OFilterItemExchange*>(m_pTransferable); } 252 253 protected: 254 virtual OLocalExchange* createExchange() const; 255 }; 256 257 //======================================================================== 258 class FmFilterNavigator : public SvTreeListBox, public SfxListener 259 { 260 enum DROP_ACTION{ DA_SCROLLUP, DA_SCROLLDOWN, DA_EXPANDNODE }; 261 262 FmFilterModel* m_pModel; 263 SvLBoxEntry* m_pEditingCurrently; 264 OFilterExchangeHelper m_aControlExchange; 265 266 267 AutoTimer m_aDropActionTimer; 268 unsigned short m_aTimerCounter; 269 Point m_aTimerTriggered; // die Position, an der der DropTimer angeschaltet wurde 270 DROP_ACTION m_aDropActionType; 271 272 public: 273 FmFilterNavigator( Window* pParent ); 274 virtual ~FmFilterNavigator(); 275 276 void UpdateContent( 277 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > & xControllers, 278 const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController > & xCurrent 279 ); 280 const FmFilterModel* GetFilterModel() const {return m_pModel;} 281 282 protected: 283 using Control::Notify; 284 285 virtual void KeyInput( const KeyEvent& rKEvt ); 286 virtual void Command( const CommandEvent& rEvt ); 287 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 288 virtual void InitEntry(SvLBoxEntry* pEntry, const XubString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind); 289 virtual sal_Bool Select( SvLBoxEntry* pEntry, sal_Bool bSelect=sal_True ); 290 virtual sal_Bool EditingEntry( SvLBoxEntry* pEntry, Selection& rSelection ); 291 virtual sal_Bool EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText ); 292 293 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ); 294 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ); 295 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ); 296 297 void DeleteSelection(); 298 void Clear(); 299 SvLBoxEntry* FindEntry(const FmFilterData* pItem) const; 300 void Insert(FmFilterData* pItem, sal_Int32 nPos); 301 void Remove(FmFilterData* pItem); 302 303 DECL_LINK(OnRemove, SvLBoxEntry*); 304 DECL_LINK(OnEdited, SvLBoxEntry*); 305 DECL_LINK(OnDropActionTimer, void*); 306 307 private: 308 /** returns the first form item and the selected FilterItems in the vector 309 @param _rItemList 310 Is filled inside. <OUT/> 311 @return 312 The first form item. 313 */ 314 FmFormItem* getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList); 315 /* inserts the filter items into the tree model and creates new FilterItems if needed. 316 @param _rFilterList 317 The items which should be inserted. 318 @param _pTargetItems 319 The target where to insert the items. 320 @param _bCopy 321 If <TRUE/> the items will not be removed from the model, otherwise they will. 322 */ 323 void insertFilterItem(const ::std::vector<FmFilterItem*>& _rFilterList,FmFilterItems* _pTargetItems,sal_Bool _bCopy = sal_False); 324 SvLBoxEntry* getPrevEntry(SvLBoxEntry* _pStartWith = NULL); 325 SvLBoxEntry* getNextEntry(SvLBoxEntry* _pStartWith = NULL); 326 327 using SvTreeListBox::Select; 328 using SvTreeListBox::ExecuteDrop; 329 using SvTreeListBox::Insert; 330 }; 331 332 //======================================================================== 333 class FmFilterNavigatorWin : public SfxDockingWindow, public SfxControllerItem 334 { 335 private: 336 FmFilterNavigator* m_pNavigator; 337 338 protected: 339 virtual void Resize(); 340 virtual sal_Bool Close(); 341 virtual Size CalcDockingSize( SfxChildAlignment ); 342 virtual SfxChildAlignment CheckAlignment( SfxChildAlignment, SfxChildAlignment ); 343 344 public: 345 FmFilterNavigatorWin( SfxBindings *pBindings, SfxChildWindow *pMgr, 346 Window* pParent ); 347 virtual ~FmFilterNavigatorWin(); 348 349 void UpdateContent( FmFormShell* pFormShell ); 350 void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ); 351 void FillInfo( SfxChildWinInfo& rInfo ) const; 352 353 using SfxDockingWindow::StateChanged; 354 355 virtual void GetFocus(); 356 }; 357 358 //======================================================================== 359 class FmFilterNavigatorWinMgr : public SfxChildWindow 360 { 361 public: 362 FmFilterNavigatorWinMgr( Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, 363 SfxChildWinInfo *pInfo ); 364 SFX_DECL_CHILDWINDOW( FmFilterNavigatorWinMgr ); 365 }; 366 367 //........................................................................ 368 } // namespace svxform 369 //........................................................................ 370 371 #endif // _SVX_FILTNAV_HXX 372 373