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_DATANAVI_HXX 28 #define _SVX_DATANAVI_HXX 29 30 #include <vcl/dialog.hxx> 31 #include <vcl/fixed.hxx> 32 #include <vcl/lstbox.hxx> 33 #include <vcl/menubtn.hxx> 34 #include <vcl/msgbox.hxx> 35 #include <vcl/tabctrl.hxx> 36 #include <vcl/tabpage.hxx> 37 #include <vcl/toolbox.hxx> 38 #include <svtools/inettbc.hxx> 39 #include <svtools/svmedit.hxx> 40 #include <svtools/svtreebx.hxx> 41 #include <sfx2/dockwin.hxx> 42 #include <sfx2/ctrlitem.hxx> 43 #include <svx/simptabl.hxx> 44 #include <rtl/ref.hxx> 45 #include <com/sun/star/beans/XPropertySet.hpp> 46 #include <com/sun/star/container/XContainer.hpp> 47 #include <com/sun/star/container/XNameContainer.hpp> 48 #include <com/sun/star/frame/XFrame.hpp> 49 #include <com/sun/star/xforms/XFormsUIHelper1.hpp> 50 #include <com/sun/star/xforms/XModel.hpp> 51 #include <com/sun/star/xforms/XSubmission.hpp> 52 #include <com/sun/star/xml/dom/XNode.hpp> 53 #include <com/sun/star/xml/dom/events/XEventTarget.hpp> 54 55 #include "datalistener.hxx" 56 #include <vector> 57 58 // forward --------------------------------------------------------------- 59 60 class FmFormShell; 61 62 //======================================================================== 63 //............................................................................ 64 namespace svxform 65 { 66 //............................................................................ 67 68 enum DataGroupType 69 { 70 DGTUnknown = 0, 71 DGTInstance, 72 DGTSubmission, 73 DGTBinding 74 }; 75 76 enum DataItemType 77 { 78 DITNone = 0, 79 DITText, 80 DITAttribute, 81 DITElement, 82 DITBinding 83 }; 84 85 struct ItemNode; 86 class XFormsPage; 87 class DataNavigatorWindow; 88 class AddInstanceDialog; 89 90 typedef ::com::sun::star::uno::Reference< 91 ::com::sun::star::xforms::XFormsUIHelper1 > XFormsUIHelper1_ref; 92 typedef ::com::sun::star::uno::Reference< 93 ::com::sun::star::xml::dom::XNode > XNode_ref; 94 typedef ::com::sun::star::uno::Reference< 95 ::com::sun::star::beans::XPropertySet > XPropertySet_ref; 96 typedef ::com::sun::star::uno::Reference< 97 ::com::sun::star::xforms::XModel > XModel_ref; 98 typedef ::com::sun::star::uno::Reference< 99 ::com::sun::star::container::XContainer > XContainer_ref; 100 typedef ::com::sun::star::uno::Reference< 101 ::com::sun::star::container::XNameContainer > XNameContainer_ref; 102 typedef ::com::sun::star::uno::Reference< 103 ::com::sun::star::frame::XFrame > XFrame_ref; 104 typedef ::com::sun::star::uno::Reference< 105 ::com::sun::star::frame::XModel > XFrameModel_ref; 106 typedef ::com::sun::star::uno::Reference< 107 ::com::sun::star::xml::dom::events::XEventTarget > XEventTarget_ref; 108 typedef ::com::sun::star::uno::Reference< 109 ::com::sun::star::xforms::XSubmission > XSubmission_ref; 110 111 typedef ::com::sun::star::uno::Sequence< 112 ::com::sun::star::beans::PropertyValue > PropertyValue_seq; 113 114 typedef std::vector< XContainer_ref > ContainerList; 115 typedef std::vector< XEventTarget_ref > EventTargetList; 116 117 //======================================================================== 118 class DataTreeListBox : public SvTreeListBox 119 { 120 private: 121 XFormsPage* m_pXFormsPage; 122 DataGroupType m_eGroup; 123 124 protected: 125 using SvTreeListBox::ExecuteDrop; 126 127 public: 128 DataTreeListBox( XFormsPage* pPage, DataGroupType _eGroup, const ResId& rResId ); 129 ~DataTreeListBox(); 130 131 virtual PopupMenu* CreateContextMenu( void ); 132 virtual void ExcecuteContextMenuAction( sal_uInt16 _nSelectedPopupEntry ); 133 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ); 134 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ); 135 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ); 136 137 void DeleteAndClear(); 138 void RemoveEntry( SvLBoxEntry* _pEntry ); 139 }; 140 141 //======================================================================== 142 class XFormsPage : public TabPage 143 { 144 private: 145 ToolBox m_aToolBox; 146 DataTreeListBox m_aItemList; 147 148 XFormsUIHelper1_ref m_xUIHelper; 149 150 DataNavigatorWindow* m_pNaviWin; 151 bool m_bHasModel; 152 DataGroupType m_eGroup; 153 ImageList m_TbxImageList; 154 ImageList m_TbxHCImageList; 155 // these strings are not valid on the Submission and Binding Page 156 // mb: furthermore these are properties of an instance, thus 157 // it would be much better to get/set them through the UIHelper 158 // interface. 159 String m_sInstanceName; 160 String m_sInstanceURL; 161 bool m_bLinkOnce; 162 163 DECL_LINK( TbxSelectHdl, ToolBox * ); 164 DECL_LINK( ItemSelectHdl, DataTreeListBox * ); 165 166 void AddChildren( SvLBoxEntry* _pParent, 167 const ImageList& _rImgLst, 168 const XNode_ref& _xNode ); 169 bool DoToolBoxAction( sal_uInt16 _nToolBoxID ); 170 SvLBoxEntry* AddEntry( ItemNode* _pNewNode, bool _bIsElement ); 171 SvLBoxEntry* AddEntry( const XPropertySet_ref& _rPropSet ); 172 void EditEntry( const XPropertySet_ref& _rPropSet ); 173 bool RemoveEntry(); 174 175 protected: 176 virtual long Notify( NotifyEvent& rNEvt ); 177 178 public: 179 XFormsPage( Window* pParent, DataNavigatorWindow* _pNaviWin, DataGroupType _eGroup ); 180 ~XFormsPage(); 181 182 virtual void Resize(); 183 184 inline bool HasModel() const { return m_bHasModel; } 185 String SetModel( const XModel_ref& _xModel, sal_uInt16 _nPagePos ); 186 void ClearModel(); 187 String LoadInstance( const PropertyValue_seq& _xPropSeq, 188 const ImageList& _rImgLst ); 189 190 bool DoMenuAction( sal_uInt16 _nMenuID ); 191 void EnableMenuItems( Menu* _pMenu ); 192 193 inline SvLBoxEntry* GetSelectedItem() const { return m_aItemList.FirstSelected(); } 194 inline const String& GetInstanceName() const { return m_sInstanceName; } 195 inline const String& GetInstanceURL() const { return m_sInstanceURL; } 196 inline bool GetLinkOnce() const { return m_bLinkOnce; } 197 inline void SetInstanceName( const String &name ) { m_sInstanceName=name; } 198 inline void SetInstanceURL( const String &url ) { m_sInstanceURL=url; } 199 inline void SetLinkOnce( bool bLinkOnce ) { m_bLinkOnce=bLinkOnce; } 200 201 typedef com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> XPropertySet_t; 202 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode> XNode_t; 203 204 inline XPropertySet_t GetBindingForNode( const XNode_t &xNode ) { return m_xUIHelper->getBindingForNode(xNode,true); } 205 inline String GetServiceNameForNode( const XNode_t &xNode ) { return m_xUIHelper->getDefaultServiceNameForNode(xNode); } 206 inline XFormsUIHelper1_ref GetXFormsHelper( void ) const { return m_xUIHelper; } 207 }; 208 209 //======================================================================== 210 211 typedef std::vector< XFormsPage* > PageList; 212 typedef ::rtl::Reference < DataListener > DataListener_ref; 213 214 class DataNavigatorWindow : public Window 215 { 216 private: 217 218 ListBox m_aModelsBox; 219 MenuButton m_aModelBtn; 220 TabControl m_aTabCtrl; 221 MenuButton m_aInstanceBtn; 222 223 XFormsPage* m_pInstPage; 224 XFormsPage* m_pSubmissionPage; 225 XFormsPage* m_pBindingPage; 226 227 long m_nMinWidth; 228 long m_nMinHeight; 229 long m_nBorderHeight; 230 sal_uInt16 m_nLastSelectedPos; 231 bool m_bShowDetails; 232 bool m_bIsNotifyDisabled; 233 Size m_a2Size; 234 Size m_a3Size; 235 ImageList m_aItemImageList; 236 ImageList m_aItemHCImageList; 237 PageList m_aPageList; 238 ContainerList m_aContainerList; 239 EventTargetList m_aEventTargetList; 240 Timer m_aUpdateTimer; 241 242 DataListener_ref m_xDataListener; 243 XNameContainer_ref m_xDataContainer; 244 XFrame_ref m_xFrame; 245 XFrameModel_ref m_xFrameModel; 246 247 DECL_LINK( ModelSelectHdl, ListBox * ); 248 DECL_LINK( MenuSelectHdl, MenuButton * ); 249 DECL_LINK( MenuActivateHdl, MenuButton * ); 250 DECL_LINK( ActivatePageHdl, TabControl* ); 251 DECL_LINK( UpdateHdl, Timer* ); 252 253 XFormsPage* GetCurrentPage( sal_uInt16& rCurId ); 254 void LoadModels(); 255 void SetPageModel(); 256 void ClearAllPageModels( bool bClearPages ); 257 void InitPages(); 258 void CreateInstancePage( const PropertyValue_seq& _xPropSeq ); 259 bool HasFirstInstancePage() const; 260 sal_uInt16 GetNewPageId() const; 261 262 protected: 263 virtual void Resize(); 264 265 public: 266 DataNavigatorWindow( Window* pParent, SfxBindings* pBindings ); 267 ~DataNavigatorWindow(); 268 269 void SetDocModified(); 270 void NotifyChanges( bool _bLoadAll = false ); 271 void AddContainerBroadcaster( const XContainer_ref& xContainer ); 272 void AddEventBroadcaster( const XEventTarget_ref& xTarget ); 273 void RemoveBroadcaster(); 274 275 inline const ImageList& GetItemImageList() const { return m_aItemImageList; } 276 inline const ImageList& GetItemHCImageList() const { return m_aItemHCImageList; } 277 inline bool IsShowDetails() const { return m_bShowDetails; } 278 inline void DisableNotify( bool _bDisable ) { m_bIsNotifyDisabled = _bDisable; } 279 }; 280 281 //======================================================================== 282 class DataNavigator : public SfxDockingWindow, public SfxControllerItem 283 { 284 private: 285 DataNavigatorWindow m_aDataWin; 286 287 protected: 288 virtual void Resize(); 289 virtual sal_Bool Close(); 290 virtual void GetFocus(); 291 virtual Size CalcDockingSize( SfxChildAlignment ); 292 virtual SfxChildAlignment CheckAlignment( SfxChildAlignment, SfxChildAlignment ); 293 294 public: 295 DataNavigator( SfxBindings* pBindings, SfxChildWindow* pMgr, Window* pParent ); 296 virtual ~DataNavigator(); 297 298 using Window::Update; 299 using SfxDockingWindow::StateChanged; 300 301 void Update( FmFormShell* pFormShell ); 302 void StateChanged( sal_uInt16 nSID, SfxItemState eState, 303 const SfxPoolItem* pState ); 304 }; 305 306 //======================================================================== 307 class SVX_DLLPUBLIC DataNavigatorManager : public SfxChildWindow 308 { 309 public: 310 SVX_DLLPRIVATE DataNavigatorManager( Window* pParent, sal_uInt16 nId, 311 SfxBindings* pBindings, SfxChildWinInfo* pInfo ); 312 SFX_DECL_CHILDWINDOW( DataNavigatorManager ); 313 }; 314 315 //======================================================================== 316 class AddDataItemDialog : public ModalDialog 317 { 318 private: 319 320 FixedLine m_aItemFL; 321 FixedText m_aNameFT; 322 Edit m_aNameED; 323 FixedText m_aDefaultFT; 324 Edit m_aDefaultED; 325 PushButton m_aDefaultBtn; 326 327 FixedLine m_aSettingsFL; 328 FixedText m_aDataTypeFT; 329 ListBox m_aDataTypeLB; 330 331 CheckBox m_aRequiredCB; 332 PushButton m_aRequiredBtn; 333 CheckBox m_aRelevantCB; 334 PushButton m_aRelevantBtn; 335 CheckBox m_aConstraintCB; 336 PushButton m_aConstraintBtn; 337 CheckBox m_aReadonlyCB; 338 PushButton m_aReadonlyBtn; 339 CheckBox m_aCalculateCB; 340 PushButton m_aCalculateBtn; 341 342 FixedLine m_aButtonsFL; 343 OKButton m_aOKBtn; 344 CancelButton m_aEscBtn; 345 HelpButton m_aHelpBtn; 346 347 XFormsUIHelper1_ref m_xUIHelper; 348 XPropertySet_ref m_xBinding; 349 XPropertySet_ref m_xTempBinding; 350 351 ItemNode* m_pItemNode; 352 DataItemType m_eItemType; 353 String m_sFL_Element; 354 String m_sFL_Attribute; 355 String m_sFL_Binding; 356 String m_sFT_BindingExp; 357 358 DECL_LINK( CheckHdl, CheckBox * ); 359 DECL_LINK( ConditionHdl, PushButton * ); 360 DECL_LINK( OKHdl, OKButton * ); 361 362 void InitDialog(); 363 void InitFromNode(); 364 void InitDataTypeBox(); 365 366 public: 367 AddDataItemDialog( 368 Window* pParent, ItemNode* _pNode, const XFormsUIHelper1_ref& _rUIHelper ); 369 ~AddDataItemDialog(); 370 371 void InitText( DataItemType _eType ); 372 }; 373 374 //======================================================================== 375 class AddConditionDialog : public ModalDialog 376 { 377 private: 378 FixedText m_aConditionFT; 379 MultiLineEdit m_aConditionED; 380 FixedText m_aResultFT; 381 FixedText m_aResultWin; 382 PushButton m_aEditNamespacesBtn; 383 FixedLine m_aButtonsFL; 384 OKButton m_aOKBtn; 385 CancelButton m_aEscBtn; 386 HelpButton m_aHelpBtn; 387 388 Timer m_aResultTimer; 389 ::rtl::OUString m_sPropertyName; 390 391 XFormsUIHelper1_ref m_xUIHelper; 392 XPropertySet_ref m_xBinding; 393 394 DECL_LINK( ModifyHdl, MultiLineEdit * ); 395 DECL_LINK( ResultHdl, Timer * ); 396 DECL_LINK( EditHdl, PushButton * ); 397 DECL_LINK( OKHdl, OKButton * ); 398 399 public: 400 AddConditionDialog( Window* pParent, 401 const ::rtl::OUString& _rPropertyName, const XPropertySet_ref& _rBinding ); 402 ~AddConditionDialog(); 403 404 inline XFormsUIHelper1_ref GetUIHelper() const { return m_xUIHelper; } 405 inline String GetCondition() const { return m_aConditionED.GetText(); } 406 inline void SetCondition( const String& _rCondition ); 407 }; 408 409 inline void AddConditionDialog::SetCondition( const String& _rCondition ) 410 { 411 m_aConditionED.SetText( _rCondition ); 412 m_aResultTimer.Start(); 413 } 414 415 //======================================================================== 416 class NamespaceItemDialog : public ModalDialog 417 { 418 private: 419 typedef std::vector< ::rtl::OUString > PrefixList; 420 421 FixedText m_aNamespacesFT; 422 SvxSimpleTable m_aNamespacesList; 423 PushButton m_aAddNamespaceBtn; 424 PushButton m_aEditNamespaceBtn; 425 PushButton m_aDeleteNamespaceBtn; 426 FixedLine m_aButtonsFL; 427 OKButton m_aOKBtn; 428 CancelButton m_aEscBtn; 429 HelpButton m_aHelpBtn; 430 431 AddConditionDialog* m_pConditionDlg; 432 PrefixList m_aRemovedList; 433 434 XNameContainer_ref& m_rNamespaces; 435 436 DECL_LINK( SelectHdl, SvxSimpleTable * ); 437 DECL_LINK( ClickHdl, PushButton * ); 438 DECL_LINK( OKHdl, OKButton * ); 439 440 void LoadNamespaces(); 441 442 public: 443 NamespaceItemDialog( AddConditionDialog* pParent, XNameContainer_ref& _rContainer ); 444 ~NamespaceItemDialog(); 445 }; 446 447 //======================================================================== 448 class ManageNamespaceDialog : public ModalDialog 449 { 450 private: 451 FixedText m_aPrefixFT; 452 Edit m_aPrefixED; 453 FixedText m_aUrlFT; 454 Edit m_aUrlED; 455 FixedLine m_aButtonsFL; 456 OKButton m_aOKBtn; 457 CancelButton m_aEscBtn; 458 HelpButton m_aHelpBtn; 459 460 AddConditionDialog* m_pConditionDlg; 461 462 DECL_LINK( OKHdl, OKButton * ); 463 464 public: 465 ManageNamespaceDialog( Window* pParent, AddConditionDialog* _pCondDlg, bool _bIsEdit ); 466 ~ManageNamespaceDialog(); 467 468 inline void SetNamespace( const String& _rPrefix, const String& _rURL ); 469 inline String GetPrefix() const { return m_aPrefixED.GetText(); } 470 inline String GetURL() const { return m_aUrlED.GetText(); } 471 }; 472 473 void ManageNamespaceDialog::SetNamespace( const String& _rPrefix, const String& _rURL ) 474 { 475 m_aPrefixED.SetText( _rPrefix ); 476 m_aUrlED.SetText( _rURL ); 477 } 478 479 //======================================================================== 480 class AddSubmissionDialog : public ModalDialog 481 { 482 private: 483 FixedLine m_aSubmissionFL; 484 FixedText m_aNameFT; 485 Edit m_aNameED; 486 FixedText m_aActionFT; 487 Edit m_aActionED; 488 FixedText m_aMethodFT; 489 ListBox m_aMethodLB; 490 FixedText m_aRefFT; 491 Edit m_aRefED; 492 PushButton m_aRefBtn; 493 FixedText m_aBindFT; 494 ListBox m_aBindLB; 495 FixedText m_aReplaceFT; 496 ListBox m_aReplaceLB; 497 498 FixedLine m_aButtonsFL; 499 OKButton m_aOKBtn; 500 CancelButton m_aEscBtn; 501 HelpButton m_aHelpBtn; 502 503 ItemNode* m_pItemNode; 504 505 XFormsUIHelper1_ref m_xUIHelper; 506 XSubmission_ref m_xNewSubmission; 507 XPropertySet_ref m_xSubmission; 508 XPropertySet_ref m_xTempBinding; 509 XPropertySet_ref m_xCreatedBinding; 510 511 DECL_LINK( RefHdl, PushButton * ); 512 DECL_LINK( OKHdl, OKButton * ); 513 514 void FillAllBoxes(); 515 516 public: 517 AddSubmissionDialog( Window* pParent, ItemNode* _pNode, 518 const XFormsUIHelper1_ref& _rUIHelper ); 519 ~AddSubmissionDialog(); 520 521 inline const XSubmission_ref& GetNewSubmission() const { return m_xNewSubmission; } 522 }; 523 524 //======================================================================== 525 class AddModelDialog : public ModalDialog 526 { 527 private: 528 FixedLine m_aModelFL; 529 FixedText m_aNameFT; 530 Edit m_aNameED; 531 CheckBox m_aModifyCB; 532 FixedLine m_aButtonsFL; 533 OKButton m_aOKBtn; 534 CancelButton m_aEscBtn; 535 HelpButton m_aHelpBtn; 536 537 public: 538 AddModelDialog( Window* pParent, bool _bEdit ); 539 ~AddModelDialog(); 540 541 inline String GetName() const { return m_aNameED.GetText(); } 542 inline void SetName( const String& _rName ) { m_aNameED.SetText( _rName );} 543 544 inline bool GetModifyDoc() const { return bool( m_aModifyCB.IsChecked() ); } 545 inline void SetModifyDoc( const bool _bModify ) { m_aModifyCB.Check( _bModify ); } 546 }; 547 548 //======================================================================== 549 class AddInstanceDialog : public ModalDialog 550 { 551 private: 552 FixedLine m_aInstanceFL; 553 FixedText m_aNameFT; 554 Edit m_aNameED; 555 FixedText m_aURLFT; 556 SvtURLBox m_aURLED; 557 PushButton m_aFilePickerBtn; 558 CheckBox m_aLinkInstanceCB; 559 FixedLine m_aButtonsFL; 560 OKButton m_aOKBtn; 561 CancelButton m_aEscBtn; 562 HelpButton m_aHelpBtn; 563 564 String m_sAllFilterName; 565 566 DECL_LINK( FilePickerHdl, PushButton * ); 567 568 public: 569 AddInstanceDialog( Window* pParent, bool _bEdit ); 570 ~AddInstanceDialog(); 571 572 inline void SetRenameMode(); 573 inline String GetName() const { return m_aNameED.GetText(); } 574 inline void SetName( const String& _rName ) { m_aNameED.SetText( _rName );} 575 inline String GetURL() const { return m_aURLED.GetText(); } 576 inline void SetURL( const String& _rURL ) { m_aURLED.SetText( _rURL );} 577 inline bool IsLinkInstance() const { return ( m_aLinkInstanceCB.IsChecked() != sal_False ); } 578 inline void SetLinkInstance( bool _bLink ) { m_aLinkInstanceCB.Check( _bLink != false ); } 579 }; 580 581 inline void AddInstanceDialog::SetRenameMode() 582 { 583 m_aURLFT.Disable(); 584 m_aURLED.Disable(); 585 m_aFilePickerBtn.Disable(); 586 m_aLinkInstanceCB.Disable(); 587 } 588 589 //======================================================================== 590 class LinkedInstanceWarningBox : public MessBox 591 { 592 public: 593 LinkedInstanceWarningBox( Window* pParent ); 594 }; 595 596 //............................................................................ 597 } // namespace svxform 598 //............................................................................ 599 600 #endif // _SVX_DATANAVI_HXX 601 602