1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SVX_SOURCE_INC_DATANAVI_HXX
20 #define INCLUDED_SVX_SOURCE_INC_DATANAVI_HXX
22 #include <config_options.h>
23 #include <o3tl/sorted_vector.hxx>
24 #include <vcl/builderpage.hxx>
25 #include <vcl/idle.hxx>
26 #include <vcl/transfer.hxx>
27 #include <vcl/weld.hxx>
28 #include <svtools/inettbc.hxx>
29 #include <sfx2/dockwin.hxx>
30 #include <sfx2/childwin.hxx>
31 #include <sfx2/ctrlitem.hxx>
32 #include <svx/dialmgr.hxx>
33 #include <svx/strings.hrc>
34 #include <svx/svxdllapi.h>
35 #include <rtl/ref.hxx>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XContainer.hpp>
38 #include <com/sun/star/container/XNameContainer.hpp>
39 #include <com/sun/star/frame/XFrame.hpp>
40 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
41 #include <com/sun/star/xforms/XModel.hpp>
42 #include <com/sun/star/xforms/XSubmission.hpp>
43 #include <com/sun/star/xml/dom/XNode.hpp>
44 #include <com/sun/star/xml/dom/events/XEventTarget.hpp>
46 #include "datalistener.hxx"
49 #include <string_view>
78 class DataNavigatorWindow
;
79 class AddInstanceDialog
;
84 OUString m_sInstance_UI
;
87 static constexpr OUStringLiteral m_sDoc_API
= u
"all";
88 static constexpr OUStringLiteral m_sInstance_API
= u
"instance";
89 static constexpr OUStringLiteral m_sNone_API
= u
"none";
91 ReplaceString( const ReplaceString
& ) = delete;
96 m_sDoc_UI
= SvxResId(RID_STR_REPLACE_DOC
);
97 m_sInstance_UI
= SvxResId(RID_STR_REPLACE_INST
);
98 m_sNone_UI
= SvxResId(RID_STR_REPLACE_NONE
);
101 /** convert submission replace string from API value to UI value.
102 Use 'none' as default. */
103 OUString
const & toUI( std::u16string_view rStr
) const
105 if( rStr
== m_sDoc_API
)
107 else if( rStr
== m_sInstance_API
)
108 return m_sInstance_UI
;
113 /** convert submission replace string from UI to API.
114 Use 'none' as default. */
115 OUString
toAPI( std::u16string_view rStr
) const
117 if( rStr
== m_sDoc_UI
)
119 else if( rStr
== m_sInstance_UI
)
120 return m_sInstance_API
;
132 static constexpr OUStringLiteral m_sPost_API
= u
"post";
133 static constexpr OUStringLiteral m_sPut_API
= u
"put";
134 static constexpr OUStringLiteral m_sGet_API
= u
"get";
136 MethodString( const MethodString
& ) = delete;
142 m_sPost_UI
= SvxResId(RID_STR_METHOD_POST
);
143 m_sPut_UI
= SvxResId(RID_STR_METHOD_PUT
);
144 m_sGet_UI
= SvxResId(RID_STR_METHOD_GET
);
147 /** convert from API to UI; put is default. */
148 OUString
const & toUI( std::u16string_view rStr
) const
150 if( rStr
== m_sGet_API
)
152 else if( rStr
== m_sPost_API
)
158 /** convert from UI to API; put is default */
159 OUString
toAPI( std::u16string_view rStr
) const
161 if( rStr
== m_sGet_UI
)
163 else if( rStr
== m_sPost_UI
)
170 class DataTreeDropTarget final
: public DropTargetHelper
173 virtual sal_Int8
AcceptDrop(const AcceptDropEvent
& rEvt
) override
;
174 virtual sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
) override
;
177 DataTreeDropTarget(weld::TreeView
& rWidget
);
180 class XFormsPage final
: public BuilderPage
183 MethodString m_aMethodString
;
184 ReplaceString m_aReplaceString
;
186 weld::Container
* m_pParent
;
187 std::unique_ptr
<weld::Toolbar
> m_xToolBox
;
188 std::unique_ptr
<weld::Menu
> m_xMenu
;
189 std::unique_ptr
<weld::TreeView
> m_xItemList
;
190 std::unique_ptr
<weld::TreeIter
> m_xScratchIter
;
192 o3tl::sorted_vector
<OUString
> m_aRemovedMenuEntries
;
194 DataTreeDropTarget m_aDropHelper
;
196 css::uno::Reference
< css::xforms::XFormsUIHelper1
>
199 DataNavigatorWindow
* m_pNaviWin
;
201 DataGroupType m_eGroup
;
202 // these strings are not valid on the Submission and Binding Page
203 // mb: furthermore these are properties of an instance, thus
204 // it would be much better to get/set them through the UIHelper
206 OUString m_sInstanceName
;
207 OUString m_sInstanceURL
;
210 DECL_LINK(TbxSelectHdl
, const OUString
&, void);
211 DECL_LINK(ItemSelectHdl
, weld::TreeView
&, void);
212 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
213 DECL_LINK(PopupMenuHdl
, const CommandEvent
&, bool);
215 void AddChildren(const weld::TreeIter
* _pParent
,
216 const css::uno::Reference
< css::xml::dom::XNode
>& _xNode
);
217 bool DoToolBoxAction(std::u16string_view rToolBoxID
);
218 void AddEntry(std::unique_ptr
<ItemNode
> _pNewNode
, bool _bIsElement
, weld::TreeIter
* pRet
= nullptr);
219 void AddEntry(const css::uno::Reference
< css::beans::XPropertySet
>& _rPropSet
, weld::TreeIter
* pRet
= nullptr);
220 void EditEntry( const css::uno::Reference
< css::beans::XPropertySet
>& _rPropSet
);
225 void DeleteAndClearTree();
227 void SetMenuEntrySensitive(const OUString
& rIdent
, bool bSensitive
);
230 XFormsPage(weld::Container
* pParent
, DataNavigatorWindow
* _pNaviWin
, DataGroupType _eGroup
);
231 virtual ~XFormsPage() override
;
233 bool HasModel() const { return m_bHasModel
; }
234 OUString
SetModel( const css::uno::Reference
< css::xforms::XModel
> & _xModel
, int _nPagePos
);
236 OUString
LoadInstance(const css::uno::Sequence
< css::beans::PropertyValue
>& _xPropSeq
);
238 bool DoMenuAction(std::u16string_view rMenuID
);
239 void EnableMenuItems();
240 void SelectFirstEntry();
242 const OUString
& GetInstanceName() const { return m_sInstanceName
; }
243 const OUString
& GetInstanceURL() const { return m_sInstanceURL
; }
244 bool GetLinkOnce() const { return m_bLinkOnce
; }
245 void SetInstanceName( const OUString
&name
) { m_sInstanceName
=name
; }
246 void SetInstanceURL( const OUString
&url
) { m_sInstanceURL
=url
; }
247 void SetLinkOnce( bool bLinkOnce
) { m_bLinkOnce
=bLinkOnce
; }
249 css::uno::Reference
<css::beans::XPropertySet
>
250 GetBindingForNode( const css::uno::Reference
<css::xml::dom::XNode
> &xNode
) { return m_xUIHelper
->getBindingForNode(xNode
,true); }
251 OUString
GetServiceNameForNode( const css::uno::Reference
<css::xml::dom::XNode
> &xNode
) { return m_xUIHelper
->getDefaultServiceNameForNode(xNode
); }
252 const css::uno::Reference
< css::xforms::XFormsUIHelper1
>&
253 GetXFormsHelper() const { return m_xUIHelper
; }
256 class DataNavigatorWindow final
259 VclPtr
<vcl::Window
> m_xParent
;
260 std::unique_ptr
<weld::ComboBox
> m_xModelsBox
;
261 std::unique_ptr
<weld::MenuButton
> m_xModelBtn
;
262 std::unique_ptr
<weld::Notebook
> m_xTabCtrl
;
263 std::unique_ptr
<weld::MenuButton
> m_xInstanceBtn
;
265 std::unique_ptr
<XFormsPage
> m_xInstPage
;
266 std::unique_ptr
<XFormsPage
> m_xSubmissionPage
;
267 std::unique_ptr
<XFormsPage
> m_xBindingPage
;
269 sal_Int32 m_nLastSelectedPos
;
271 bool m_bIsNotifyDisabled
;
272 std::vector
< std::unique_ptr
<XFormsPage
> >
274 std::vector
< css::uno::Reference
< css::container::XContainer
> >
276 std::vector
< css::uno::Reference
< css::xml::dom::events::XEventTarget
> >
278 Timer m_aUpdateTimer
;
280 ::rtl::Reference
< DataListener
>
282 css::uno::Reference
< css::container::XNameContainer
>
284 css::uno::Reference
< css::frame::XFrame
>
286 css::uno::Reference
< css::frame::XModel
>
289 DECL_LINK( ModelSelectListBoxHdl
, weld::ComboBox
&, void );
290 DECL_LINK( MenuSelectHdl
, const OUString
&, void );
291 DECL_LINK( MenuActivateHdl
, weld::Toggleable
&, void );
292 DECL_LINK( ActivatePageHdl
, const OUString
&, void);
293 DECL_LINK( UpdateHdl
, Timer
*, void);
294 void ModelSelectHdl(const weld::ComboBox
*);
295 OUString
GetCurrentPage() const;
296 XFormsPage
* GetPage(const OUString
& rCurId
);
298 void SetPageModel(const OUString
& rCurId
);
299 void ClearAllPageModels( bool bClearPages
);
301 void CreateInstancePage( const css::uno::Sequence
< css::beans::PropertyValue
>& _xPropSeq
);
302 bool HasFirstInstancePage() const;
303 OUString
GetNewPageId() const;
305 static bool IsAdditionalPage(std::u16string_view rIdent
);
308 DataNavigatorWindow(vcl::Window
* pParent
, weld::Builder
& rBuilder
, SfxBindings
const * pBindings
);
309 ~DataNavigatorWindow();
311 static void SetDocModified();
312 void NotifyChanges( bool _bLoadAll
= false );
313 void AddContainerBroadcaster( const css::uno::Reference
< css::container::XContainer
> & xContainer
);
314 void AddEventBroadcaster( const css::uno::Reference
< css::xml::dom::events::XEventTarget
>& xTarget
);
315 void RemoveBroadcaster();
317 weld::Window
* GetFrameWeld() const { return m_xParent
->GetFrameWeld(); }
319 bool IsShowDetails() const { return m_bShowDetails
; }
320 void DisableNotify( bool _bDisable
) { m_bIsNotifyDisabled
= _bDisable
; }
323 class DataNavigator final
: public SfxDockingWindow
, public SfxControllerItem
326 std::unique_ptr
<DataNavigatorWindow
> m_xDataWin
;
328 virtual Size
CalcDockingSize( SfxChildAlignment
) override
;
329 virtual SfxChildAlignment
CheckAlignment( SfxChildAlignment
, SfxChildAlignment
) override
;
332 DataNavigator( SfxBindings
* pBindings
, SfxChildWindow
* pMgr
, vcl::Window
* pParent
);
333 virtual ~DataNavigator() override
;
334 virtual void dispose() override
;
336 using SfxDockingWindow::StateChanged
;
338 void StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
,
339 const SfxPoolItem
* pState
) override
;
342 class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC
) DataNavigatorManager final
: public SfxChildWindow
345 SVX_DLLPRIVATE
DataNavigatorManager( vcl::Window
* pParent
, sal_uInt16 nId
,
346 SfxBindings
* pBindings
, SfxChildWinInfo
* pInfo
);
347 SFX_DECL_CHILDWINDOW( DataNavigatorManager
);
350 class AddDataItemDialog final
: public weld::GenericDialogController
353 css::uno::Reference
< css::xforms::XFormsUIHelper1
>
355 css::uno::Reference
< css::beans::XPropertySet
>
357 css::uno::Reference
< css::beans::XPropertySet
>
360 ItemNode
* m_pItemNode
;
361 DataItemType m_eItemType
;
362 OUString m_sFL_Element
;
363 OUString m_sFL_Attribute
;
364 OUString m_sFL_Binding
;
365 OUString m_sFT_BindingExp
;
367 std::unique_ptr
<weld::Frame
> m_xItemFrame
;
368 std::unique_ptr
<weld::Label
> m_xNameFT
;
369 std::unique_ptr
<weld::Entry
> m_xNameED
;
370 std::unique_ptr
<weld::Label
> m_xDefaultFT
;
371 std::unique_ptr
<weld::Entry
> m_xDefaultED
;
372 std::unique_ptr
<weld::Button
> m_xDefaultBtn
;
373 std::unique_ptr
<weld::Widget
> m_xSettingsFrame
;
374 std::unique_ptr
<weld::ComboBox
> m_xDataTypeLB
;
375 std::unique_ptr
<weld::CheckButton
> m_xRequiredCB
;
376 std::unique_ptr
<weld::Button
> m_xRequiredBtn
;
377 std::unique_ptr
<weld::CheckButton
> m_xRelevantCB
;
378 std::unique_ptr
<weld::Button
> m_xRelevantBtn
;
379 std::unique_ptr
<weld::CheckButton
> m_xConstraintCB
;
380 std::unique_ptr
<weld::Button
> m_xConstraintBtn
;
381 std::unique_ptr
<weld::CheckButton
> m_xReadonlyCB
;
382 std::unique_ptr
<weld::Button
> m_xReadonlyBtn
;
383 std::unique_ptr
<weld::CheckButton
> m_xCalculateCB
;
384 std::unique_ptr
<weld::Button
> m_xCalculateBtn
;
385 std::unique_ptr
<weld::Button
> m_xOKBtn
;
387 void Check(const weld::Toggleable
* pBox
);
388 DECL_LINK(CheckHdl
, weld::Toggleable
&, void);
389 DECL_LINK(ConditionHdl
, weld::Button
&, void);
390 DECL_LINK(OKHdl
, weld::Button
&, void);
394 void InitDataTypeBox();
398 weld::Window
* pParent
, ItemNode
* _pNode
,
399 const css::uno::Reference
< css::xforms::XFormsUIHelper1
>& _rUIHelper
);
400 virtual ~AddDataItemDialog() override
;
402 void InitText( DataItemType _eType
);
405 class AddConditionDialog final
: public weld::GenericDialogController
409 OUString m_sPropertyName
;
411 css::uno::Reference
< css::xforms::XFormsUIHelper1
>
413 css::uno::Reference
< css::beans::XPropertySet
>
416 std::unique_ptr
<weld::TextView
> m_xConditionED
;
417 std::unique_ptr
<weld::TextView
> m_xResultWin
;
418 std::unique_ptr
<weld::Button
> m_xEditNamespacesBtn
;
419 std::unique_ptr
<weld::Button
> m_xOKBtn
;
421 DECL_LINK(ModifyHdl
, weld::TextView
&, void);
422 DECL_LINK(ResultHdl
, Timer
*, void);
423 DECL_LINK(EditHdl
, weld::Button
&, void);
424 DECL_LINK(OKHdl
, weld::Button
&, void);
427 AddConditionDialog(weld::Window
* pParent
,
428 OUString _aPropertyName
, const css::uno::Reference
< css::beans::XPropertySet
>& _rBinding
);
429 virtual ~AddConditionDialog() override
;
431 const css::uno::Reference
< css::xforms::XFormsUIHelper1
>& GetUIHelper() const { return m_xUIHelper
; }
432 OUString
GetCondition() const { return m_xConditionED
->get_text(); }
433 void SetCondition(const OUString
& _rCondition
)
435 m_xConditionED
->set_text(_rCondition
);
436 m_aResultIdle
.Start();
440 class NamespaceItemDialog final
: public weld::GenericDialogController
443 AddConditionDialog
* m_pConditionDlg
;
444 std::vector
< OUString
> m_aRemovedList
;
446 css::uno::Reference
< css::container::XNameContainer
>&
449 std::unique_ptr
<weld::TreeView
> m_xNamespacesList
;
450 std::unique_ptr
<weld::Button
> m_xAddNamespaceBtn
;
451 std::unique_ptr
<weld::Button
> m_xEditNamespaceBtn
;
452 std::unique_ptr
<weld::Button
> m_xDeleteNamespaceBtn
;
453 std::unique_ptr
<weld::Button
> m_xOKBtn
;
455 DECL_LINK(SelectHdl
, weld::TreeView
&, void);
456 DECL_LINK(ClickHdl
, weld::Button
&, void);
457 DECL_LINK(OKHdl
, weld::Button
&, void);
459 void LoadNamespaces();
462 NamespaceItemDialog(AddConditionDialog
* pParent
, css::uno::Reference
< css::container::XNameContainer
>& _rContainer
);
463 virtual ~NamespaceItemDialog() override
;
466 class ManageNamespaceDialog final
: public weld::GenericDialogController
469 AddConditionDialog
* m_pConditionDlg
;
471 std::unique_ptr
<weld::Entry
> m_xPrefixED
;
472 std::unique_ptr
<weld::Entry
> m_xUrlED
;
473 std::unique_ptr
<weld::Button
> m_xOKBtn
;
474 std::unique_ptr
<weld::Label
> m_xAltTitle
;
476 DECL_LINK(OKHdl
, weld::Button
&, void);
479 ManageNamespaceDialog(weld::Window
* pParent
, AddConditionDialog
* _pCondDlg
, bool bIsEdit
);
480 virtual ~ManageNamespaceDialog() override
;
482 void SetNamespace(const OUString
& _rPrefix
, const OUString
& _rURL
)
484 m_xPrefixED
->set_text(_rPrefix
);
485 m_xUrlED
->set_text(_rURL
);
487 OUString
GetPrefix() const { return m_xPrefixED
->get_text(); }
488 OUString
GetURL() const { return m_xUrlED
->get_text(); }
491 class AddSubmissionDialog final
: public weld::GenericDialogController
494 MethodString m_aMethodString
;
495 ReplaceString m_aReplaceString
;
497 ItemNode
* m_pItemNode
;
499 css::uno::Reference
< css::xforms::XFormsUIHelper1
>
501 css::uno::Reference
< css::xforms::XSubmission
>
503 css::uno::Reference
< css::beans::XPropertySet
>
505 css::uno::Reference
< css::beans::XPropertySet
>
507 css::uno::Reference
< css::beans::XPropertySet
>
510 std::unique_ptr
<weld::Entry
> m_xNameED
;
511 std::unique_ptr
<weld::Entry
> m_xActionED
;
512 std::unique_ptr
<weld::ComboBox
> m_xMethodLB
;
513 std::unique_ptr
<weld::Entry
> m_xRefED
;
514 std::unique_ptr
<weld::Button
> m_xRefBtn
;
515 std::unique_ptr
<weld::ComboBox
> m_xBindLB
;
516 std::unique_ptr
<weld::ComboBox
> m_xReplaceLB
;
517 std::unique_ptr
<weld::Button
> m_xOKBtn
;
519 DECL_LINK(RefHdl
, weld::Button
&, void);
520 DECL_LINK(OKHdl
, weld::Button
&, void);
525 AddSubmissionDialog(weld::Window
* pParent
, ItemNode
* pNode
,
526 const css::uno::Reference
< css::xforms::XFormsUIHelper1
>& rUIHelper
);
527 virtual ~AddSubmissionDialog() override
;
529 const css::uno::Reference
< css::xforms::XSubmission
>& GetNewSubmission() const { return m_xNewSubmission
; }
532 class AddModelDialog final
: public weld::GenericDialogController
535 std::unique_ptr
<weld::Entry
> m_xNameED
;
536 std::unique_ptr
<weld::CheckButton
> m_xModifyCB
;
537 std::unique_ptr
<weld::Label
> m_xAltTitle
;
540 AddModelDialog(weld::Window
* pParent
, bool _bEdit
);
541 virtual ~AddModelDialog() override
;
543 OUString
GetName() const { return m_xNameED
->get_text(); }
544 void SetName( const OUString
& _rName
) { m_xNameED
->set_text( _rName
);}
546 bool GetModifyDoc() const { return m_xModifyCB
->get_active(); }
547 void SetModifyDoc( const bool bModify
) { m_xModifyCB
->set_active(bModify
); }
550 class AddInstanceDialog final
: public weld::GenericDialogController
553 OUString m_sAllFilterName
;
555 std::unique_ptr
<weld::Entry
> m_xNameED
;
556 std::unique_ptr
<SvtURLBox
> m_xURLED
;
557 std::unique_ptr
<weld::Button
> m_xFilePickerBtn
;
558 std::unique_ptr
<weld::CheckButton
> m_xLinkInstanceCB
;
559 std::unique_ptr
<weld::Label
> m_xAltTitle
;
561 DECL_LINK(FilePickerHdl
, weld::Button
&, void);
564 AddInstanceDialog(weld::Window
* pParent
, bool _bEdit
);
565 virtual ~AddInstanceDialog() override
;
567 OUString
GetName() const { return m_xNameED
->get_text(); }
568 void SetName( const OUString
& rName
) { m_xNameED
->set_text( rName
);}
569 OUString
GetURL() const { return m_xURLED
->get_active_text(); }
570 void SetURL( const OUString
& rURL
) { m_xURLED
->set_entry_text( rURL
);}
571 bool IsLinkInstance() const { return m_xLinkInstanceCB
->get_active(); }
572 void SetLinkInstance( bool bLink
) { m_xLinkInstanceCB
->set_active(bLink
); }
575 class LinkedInstanceWarningBox final
: public weld::MessageDialogController
578 LinkedInstanceWarningBox(weld::Widget
* pParent
);
583 #endif // INCLUDED_SVX_SOURCE_INC_DATANAVI_HXX
585 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */