Bump version to 6.4-15
[LibreOffice.git] / svx / source / form / datanavi.cxx
bloba409731f18c02d7c5ff5324d4189ce6d95cb0d2e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sal/config.h>
22 #include <memory>
24 #include <sal/macros.h>
25 #include <sal/log.hxx>
26 #include <datanavi.hxx>
27 #include <fmservs.hxx>
29 #include <bitmaps.hlst>
30 #include <fpicker/strings.hrc>
31 #include <svx/svxids.hrc>
32 #include <tools/diagnose_ex.h>
33 #include <unotools/resmgr.hxx>
34 #include <svx/xmlexchg.hxx>
35 #include <svx/fmshell.hxx>
36 #include <svtools/miscopt.hxx>
37 #include <unotools/pathoptions.hxx>
38 #include <unotools/viewoptions.hxx>
39 #include <vcl/treelistentry.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/filedlghelper.hxx>
42 #include <sfx2/objitem.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <sfx2/objsh.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <vcl/weld.hxx>
48 #include <vcl/builderfactory.hxx>
49 #include <com/sun/star/beans/PropertyAttribute.hpp>
50 #include <com/sun/star/container/XSet.hpp>
51 #include <com/sun/star/datatransfer/XTransferable.hpp>
52 #include <com/sun/star/frame/XController.hpp>
53 #include <com/sun/star/frame/XModel.hpp>
54 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
55 #include <com/sun/star/xforms/XFormsSupplier.hpp>
56 #include <com/sun/star/xml/dom/XDocument.hpp>
57 #include <com/sun/star/xml/dom/DOMException.hpp>
58 #include <com/sun/star/form/binding/XValueBinding.hpp>
59 #include <comphelper/string.hxx>
61 using namespace ::com::sun::star::beans;
62 using namespace ::com::sun::star::container;
63 using namespace ::com::sun::star::datatransfer;
64 using namespace ::com::sun::star::frame;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::xml::dom::events;
67 using namespace ::svx;
69 #define CFGNAME_DATANAVIGATOR "DataNavigator"
70 #define CFGNAME_SHOWDETAILS "ShowDetails"
71 #define MSG_VARIABLE "%1"
72 #define MODELNAME "$MODELNAME"
73 #define INSTANCENAME "$INSTANCENAME"
74 #define ELEMENTNAME "$ELEMENTNAME"
75 #define ATTRIBUTENAME "$ATTRIBUTENAME"
76 #define SUBMISSIONNAME "$SUBMISSIONNAME"
77 #define BINDINGNAME "$BINDINGNAME"
80 namespace svxform
83 // properties of instance
84 #define PN_INSTANCE_MODEL "Instance"
85 #define PN_INSTANCE_ID "ID"
86 #define PN_INSTANCE_URL "URL"
88 // properties of binding
89 #define PN_BINDING_ID "BindingID"
90 #define PN_BINDING_EXPR "BindingExpression"
91 #define PN_BINDING_MODEL "Model"
92 #define PN_BINDING_NAMESPACES "ModelNamespaces"
93 #define PN_READONLY_EXPR "ReadonlyExpression"
94 #define PN_RELEVANT_EXPR "RelevantExpression"
95 #define PN_REQUIRED_EXPR "RequiredExpression"
96 #define PN_CONSTRAINT_EXPR "ConstraintExpression"
97 #define PN_CALCULATE_EXPR "CalculateExpression"
98 #define PN_BINDING_TYPE "Type"
100 // properties of submission
101 #define PN_SUBMISSION_ID "ID"
102 #define PN_SUBMISSION_BIND "Bind"
103 #define PN_SUBMISSION_REF "Ref"
104 #define PN_SUBMISSION_ACTION "Action"
105 #define PN_SUBMISSION_METHOD "Method"
106 #define PN_SUBMISSION_REPLACE "Replace"
108 // other const strings
109 #define TRUE_VALUE "true()"
110 #define NEW_ELEMENT "newElement"
111 #define NEW_ATTRIBUTE "newAttribute"
112 #define EVENTTYPE_CHARDATA "DOMCharacterDataModified"
113 #define EVENTTYPE_ATTR "DOMAttrModified"
115 #define MIN_PAGE_COUNT 3 // at least one instance, one submission and one binding page
117 struct ItemNode
119 Reference< css::xml::dom::XNode > m_xNode;
120 Reference< XPropertySet > m_xPropSet;
122 explicit ItemNode( const Reference< css::xml::dom::XNode >& _rxNode ) :
123 m_xNode( _rxNode ) {}
124 explicit ItemNode( const Reference< XPropertySet >& _rxSet ) :
125 m_xPropSet( _rxSet ) {}
128 DataTreeListBox::DataTreeListBox(vcl::Window* pParent, WinBits nBits)
129 : SvTreeListBox(pParent, nBits)
130 , m_pXFormsPage(nullptr)
131 , m_eGroup(DGTUnknown)
132 , m_nAddId(0)
133 , m_nAddElementId(0)
134 , m_nAddAttributeId(0)
135 , m_nEditId(0)
136 , m_nRemoveId(0)
138 EnableContextMenuHandling();
140 if ( DGTInstance == m_eGroup )
141 SetDragDropMode( DragDropMode::CTRL_MOVE |DragDropMode::CTRL_COPY | DragDropMode::APP_COPY );
144 DataTreeListBox::~DataTreeListBox()
146 disposeOnce();
149 void DataTreeListBox::dispose()
151 DeleteAndClear();
152 m_xMenu.clear();
153 m_xBuilder.reset();
154 m_pXFormsPage.clear();
155 SvTreeListBox::dispose();
158 sal_Int8 DataTreeListBox::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
160 return DND_ACTION_NONE;
163 sal_Int8 DataTreeListBox::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
165 return DND_ACTION_NONE;
168 void DataTreeListBox::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
170 SvTreeListEntry* pSelected = FirstSelected();
171 if ( !pSelected )
172 // no drag without an entry
173 return;
175 if ( m_eGroup == DGTBinding )
176 // for the moment, bindings cannot be dragged.
177 // #i59395# / 2005-12-15 / frank.schoenheit@sun.com
178 return;
180 // GetServiceNameForNode() requires a datatype repository which
181 // will be automatically build if requested???
182 Reference< css::xforms::XModel > xModel( m_pXFormsPage->GetXFormsHelper(), UNO_QUERY );
183 Reference< css::xforms::XDataTypeRepository > xDataTypes =
184 xModel->getDataTypeRepository();
185 if(!xDataTypes.is())
186 return;
188 ItemNode *pItemNode = static_cast<ItemNode*>(pSelected->GetUserData());
190 if ( !pItemNode )
192 // the only known (and allowed?) case where this happens are sub-entries of a submission
193 // entry
194 DBG_ASSERT( DGTSubmission == m_eGroup, "DataTreeListBox::StartDrag: how this?" );
195 pSelected = GetParent( pSelected );
196 DBG_ASSERT( pSelected && !GetParent( pSelected ), "DataTreeListBox::StartDrag: what kind of entry *is* this?" );
197 // on the submission page, we have only top-level entries (the submission themself)
198 // plus direct children of those (facets of a submission)
199 pItemNode = pSelected ? static_cast< ItemNode* >( pSelected->GetUserData() ) : nullptr;
200 if ( !pItemNode )
201 return;
204 OXFormsDescriptor desc;
205 desc.szName = GetEntryText(pSelected);
206 if(pItemNode->m_xNode.is()) {
207 // a valid node interface tells us that we need to create a control from a binding
208 desc.szServiceName = m_pXFormsPage->GetServiceNameForNode(pItemNode->m_xNode);
209 desc.xPropSet = m_pXFormsPage->GetBindingForNode(pItemNode->m_xNode);
210 DBG_ASSERT( desc.xPropSet.is(), "DataTreeListBox::StartDrag(): invalid node binding" );
212 else {
213 desc.szServiceName = FM_COMPONENT_COMMANDBUTTON;
214 desc.xPropSet = pItemNode->m_xPropSet;
216 rtl::Reference<OXFormsTransferable> pTransferable = new OXFormsTransferable(desc);
217 EndSelection();
218 pTransferable->StartDrag( this, DND_ACTION_COPY );
221 VclPtr<PopupMenu> DataTreeListBox::CreateContextMenu()
223 m_xMenu.disposeAndClear();
224 m_xBuilder.reset(new VclBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/formdatamenu.ui", ""));
225 m_xMenu.set(m_xBuilder->get_menu("menu"));
227 if ( DGTInstance == m_eGroup )
228 m_xMenu->RemoveItem(m_xMenu->GetItemPos(m_xMenu->GetItemId("additem")));
229 else
231 m_xMenu->RemoveItem(m_xMenu->GetItemPos(m_xMenu->GetItemId("addelement")));
232 m_xMenu->RemoveItem(m_xMenu->GetItemPos(m_xMenu->GetItemId("addattribute")));
234 if ( DGTSubmission == m_eGroup )
236 m_xMenu->SetItemText(m_xMenu->GetItemId("additem"), SvxResId(RID_STR_DATANAV_ADD_SUBMISSION));
237 m_xMenu->SetItemText(m_xMenu->GetItemId("edit"), SvxResId(RID_STR_DATANAV_EDIT_SUBMISSION));
238 m_xMenu->SetItemText(m_xMenu->GetItemId("delete"), SvxResId(RID_STR_DATANAV_REMOVE_SUBMISSION));
240 else
242 m_xMenu->SetItemText(m_xMenu->GetItemId("additem"), SvxResId(RID_STR_DATANAV_ADD_BINDING));
243 m_xMenu->SetItemText(m_xMenu->GetItemId("edit"), SvxResId(RID_STR_DATANAV_EDIT_BINDING));
244 m_xMenu->SetItemText(m_xMenu->GetItemId("delete"), SvxResId(RID_STR_DATANAV_REMOVE_BINDING));
247 m_pXFormsPage->EnableMenuItems(m_xMenu.get());
248 return m_xMenu;
251 void DataTreeListBox::ExecuteContextMenuAction( sal_uInt16 _nSelectedPopupEntry )
253 if (m_xMenu->GetItemId("additem") == _nSelectedPopupEntry)
254 m_pXFormsPage->DoMenuAction(m_nAddId);
255 else if (m_xMenu->GetItemId("addelement") == _nSelectedPopupEntry)
256 m_pXFormsPage->DoMenuAction(m_nAddElementId);
257 else if (m_xMenu->GetItemId("addattribute") == _nSelectedPopupEntry)
258 m_pXFormsPage->DoMenuAction(m_nAddAttributeId);
259 else if (m_xMenu->GetItemId("edit") == _nSelectedPopupEntry)
260 m_pXFormsPage->DoMenuAction(m_nEditId);
261 else if (m_xMenu->GetItemId("delete") == _nSelectedPopupEntry)
262 m_pXFormsPage->DoMenuAction(m_nRemoveId);
265 void DataTreeListBox::RemoveEntry( SvTreeListEntry const * _pEntry )
267 if ( _pEntry )
269 delete static_cast< ItemNode* >( _pEntry->GetUserData() );
270 SvTreeListBox::GetModel()->Remove( _pEntry );
274 void DataTreeListBox::SetGroup(DataGroupType _eGroup)
276 m_eGroup = _eGroup;
279 void DataTreeListBox::SetXFormsPage(XFormsPage* _pPage)
281 m_pXFormsPage = _pPage;
284 void DataTreeListBox::SetToolBoxItemIds(sal_uInt16 _nAddId,
285 sal_uInt16 _nAddElementId,
286 sal_uInt16 _nAddAttributeId,
287 sal_uInt16 _nEditId,
288 sal_uInt16 _nRemoveId)
290 m_nAddId = _nAddId;
291 m_nAddElementId = _nAddElementId;
292 m_nAddAttributeId = _nAddAttributeId;
293 m_nEditId = _nEditId;
294 m_nRemoveId = _nRemoveId;
297 void DataTreeListBox::DeleteAndClear()
299 sal_uIntPtr i, nCount = GetEntryCount();
300 for ( i = 0; i < nCount; ++i )
302 SvTreeListEntry* pEntry = GetEntry(i);
303 if ( pEntry )
304 delete static_cast< ItemNode* >( pEntry->GetUserData() );
307 Clear();
311 // class XFormsPage
313 VCL_BUILDER_FACTORY_ARGS(DataTreeListBox, WB_BORDER)
315 XFormsPage::XFormsPage( vcl::Window* pParent, DataNavigatorWindow* _pNaviWin, DataGroupType _eGroup ) :
317 TabPage( pParent, "XFormsPage", "svx/ui/xformspage.ui" ),
318 m_pNaviWin ( _pNaviWin ),
319 m_bHasModel ( false ),
320 m_eGroup ( _eGroup ),
321 m_bLinkOnce ( false )
324 get(m_pToolBox, "toolbar");
325 get(m_pItemList, "items");
326 Size aSize(LogicToPixel(Size(63, 100), MapMode(MapUnit::MapAppFont)));
327 m_pItemList->set_width_request(aSize.Width());
328 m_pItemList->set_height_request(aSize.Height());
330 m_pItemList->SetGroup(_eGroup);
331 m_pItemList->SetXFormsPage( this );
333 m_nAddId = m_pToolBox->GetItemId("TBI_ITEM_ADD");
334 m_nAddElementId = m_pToolBox->GetItemId("TBI_ITEM_ADD_ELEMENT");
335 m_nAddAttributeId = m_pToolBox->GetItemId("TBI_ITEM_ADD_ATTRIBUTE");
336 m_nEditId = m_pToolBox->GetItemId("TBI_ITEM_EDIT");
337 m_nRemoveId = m_pToolBox->GetItemId("TBI_ITEM_REMOVE");
339 m_pItemList->SetToolBoxItemIds(m_nAddId, m_nAddElementId, m_nAddAttributeId, m_nEditId, m_nRemoveId);
341 m_pToolBox->InsertSeparator(4,5);
342 m_pToolBox->SetItemImage(m_nAddId, Image(StockImage::Yes, RID_SVXBMP_ADD));
343 m_pToolBox->SetItemImage(m_nAddElementId, Image(StockImage::Yes, RID_SVXBMP_ADD_ELEMENT));
344 m_pToolBox->SetItemImage(m_nAddAttributeId, Image(StockImage::Yes, RID_SVXBMP_ADD_ATTRIBUTE));
345 m_pToolBox->SetItemImage(m_nEditId, Image(StockImage::Yes, RID_SVXBMP_EDIT));
346 m_pToolBox->SetItemImage(m_nRemoveId, Image(StockImage::Yes, RID_SVXBMP_REMOVE));
348 if ( DGTInstance == m_eGroup )
349 m_pToolBox->RemoveItem( m_pToolBox->GetItemPos( m_nAddId ) );
350 else
352 m_pToolBox->RemoveItem( m_pToolBox->GetItemPos( m_nAddElementId ) );
353 m_pToolBox->RemoveItem( m_pToolBox->GetItemPos( m_nAddAttributeId ) );
355 if ( DGTSubmission == m_eGroup )
357 m_pToolBox->SetItemText( m_nAddId, SvxResId( RID_STR_DATANAV_ADD_SUBMISSION ) );
358 m_pToolBox->SetItemText( m_nEditId, SvxResId( RID_STR_DATANAV_EDIT_SUBMISSION ) );
359 m_pToolBox->SetItemText( m_nRemoveId, SvxResId( RID_STR_DATANAV_REMOVE_SUBMISSION ) );
361 else
363 m_pToolBox->SetItemText( m_nAddId, SvxResId( RID_STR_DATANAV_ADD_BINDING ) );
364 m_pToolBox->SetItemText( m_nEditId, SvxResId( RID_STR_DATANAV_EDIT_BINDING ) );
365 m_pToolBox->SetItemText( m_nRemoveId, SvxResId( RID_STR_DATANAV_REMOVE_BINDING ) );
369 const Size aTbxSz( m_pToolBox->CalcWindowSizePixel() );
370 m_pToolBox->SetSizePixel( aTbxSz );
371 m_pToolBox->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
372 m_pToolBox->SetSelectHdl( LINK( this, XFormsPage, TbxSelectHdl ) );
373 Point aPos = m_pItemList->GetPosPixel();
374 aPos.setY( aTbxSz.Height() );
375 m_pItemList->SetPosPixel( aPos );
377 m_pItemList->SetSelectHdl( LINK( this, XFormsPage, ItemSelectHdl ) );
378 m_pItemList->SetNodeDefaultImages();
379 WinBits nBits = WB_BORDER | WB_TABSTOP | WB_HIDESELECTION | WB_NOINITIALSELECTION;
380 if ( DGTInstance == m_eGroup || DGTSubmission == m_eGroup )
381 nBits |= WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT;
382 m_pItemList->SetStyle( m_pItemList->GetStyle() | nBits );
383 m_pItemList->Show();
384 ItemSelectHdl( m_pItemList );
387 XFormsPage::~XFormsPage()
389 disposeOnce();
392 void XFormsPage::dispose()
394 m_pToolBox.clear();
395 m_pItemList.clear();
396 m_pNaviWin.clear();
397 TabPage::dispose();
400 IMPL_LINK_NOARG(XFormsPage, TbxSelectHdl, ToolBox *, void)
402 DoToolBoxAction( m_pToolBox->GetCurItemId() );
405 IMPL_LINK_NOARG(XFormsPage, ItemSelectHdl, SvTreeListBox*, void)
407 EnableMenuItems( nullptr );
410 void XFormsPage::AddChildren(SvTreeListEntry* _pParent,
411 const Reference< css::xml::dom::XNode >& _xNode)
413 DBG_ASSERT( m_xUIHelper.is(), "XFormsPage::AddChildren(): invalid UIHelper" );
417 Reference< css::xml::dom::XNodeList > xNodeList = _xNode->getChildNodes();
418 if ( xNodeList.is() )
420 bool bShowDetails = m_pNaviWin->IsShowDetails();
421 sal_Int32 i, nNodeCount = xNodeList->getLength();
422 for ( i = 0; i < nNodeCount; ++i )
424 Reference< css::xml::dom::XNode > xChild = xNodeList->item(i);
425 css::xml::dom::NodeType eChildType = xChild->getNodeType();
426 Image aExpImg, aCollImg;
427 switch ( eChildType )
429 case css::xml::dom::NodeType_ATTRIBUTE_NODE:
430 aExpImg = aCollImg = Image(StockImage::Yes, RID_SVXBMP_ATTRIBUTE);
431 break;
432 case css::xml::dom::NodeType_ELEMENT_NODE:
433 aExpImg = aCollImg = Image(StockImage::Yes, RID_SVXBMP_ELEMENT);
434 break;
435 case css::xml::dom::NodeType_TEXT_NODE:
436 aExpImg = aCollImg = Image(StockImage::Yes, RID_SVXBMP_TEXT);
437 break;
438 default:
439 aExpImg = aCollImg = Image(StockImage::Yes, RID_SVXBMP_OTHER);
442 OUString sName = m_xUIHelper->getNodeDisplayName( xChild, bShowDetails );
443 if ( !sName.isEmpty() )
445 ItemNode* pNode = new ItemNode( xChild );
446 SvTreeListEntry* pEntry = m_pItemList->InsertEntry(
447 sName, aExpImg, aCollImg, _pParent, false, TREELIST_APPEND, pNode );
448 if ( xChild->hasAttributes() )
450 Reference< css::xml::dom::XNamedNodeMap > xMap = xChild->getAttributes();
451 if ( xMap.is() )
453 aExpImg = aCollImg = Image(StockImage::Yes, RID_SVXBMP_ATTRIBUTE);
454 sal_Int32 j, nMapLen = xMap->getLength();
455 for ( j = 0; j < nMapLen; ++j )
457 Reference< css::xml::dom::XNode > xAttr = xMap->item(j);
458 pNode = new ItemNode( xAttr );
459 OUString sAttrName =
460 m_xUIHelper->getNodeDisplayName( xAttr, bShowDetails );
461 m_pItemList->InsertEntry(
462 sAttrName, aExpImg, aCollImg,
463 pEntry, false, TREELIST_APPEND, pNode );
467 if ( xChild->hasChildNodes() )
468 AddChildren(pEntry, xChild);
473 catch( Exception& )
475 DBG_UNHANDLED_EXCEPTION("svx");
479 bool XFormsPage::DoToolBoxAction( sal_uInt16 _nToolBoxID ) {
481 bool bHandled = false;
482 bool bIsDocModified = false;
483 m_pNaviWin->DisableNotify( true );
485 if(_nToolBoxID == m_nAddId || _nToolBoxID == m_nAddElementId || _nToolBoxID == m_nAddAttributeId)
487 bHandled = true;
488 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
489 DBG_ASSERT( xModel.is(), "XFormsPage::DoToolBoxAction(): Action without model" );
490 if ( DGTSubmission == m_eGroup )
492 AddSubmissionDialog aDlg(GetFrameWeld(), nullptr, m_xUIHelper);
493 if ( aDlg.run() == RET_OK && aDlg.GetNewSubmission().is() )
497 Reference< css::xforms::XSubmission > xNewSubmission = aDlg.GetNewSubmission();
498 Reference< XSet > xSubmissions = xModel->getSubmissions();
499 xSubmissions->insert( makeAny( xNewSubmission ) );
500 SvTreeListEntry* pEntry = AddEntry( xNewSubmission );
501 m_pItemList->Select( pEntry );
502 bIsDocModified = true;
504 catch ( Exception const & )
506 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction()" );
510 else
512 DataItemType eType = DITElement;
513 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
514 std::unique_ptr<ItemNode> pNode;
515 Reference< css::xml::dom::XNode > xParentNode;
516 Reference< XPropertySet > xNewBinding;
517 const char* pResId = nullptr;
518 bool bIsElement = true;
519 if ( DGTInstance == m_eGroup )
521 if ( !m_sInstanceURL.isEmpty() )
523 LinkedInstanceWarningBox aMsgBox(GetFrameWeld());
524 if (aMsgBox.run() != RET_OK)
525 return bHandled;
528 DBG_ASSERT( pEntry, "XFormsPage::DoToolBoxAction(): no entry" );
529 ItemNode* pParentNode = static_cast< ItemNode* >( pEntry->GetUserData() );
530 DBG_ASSERT( pParentNode, "XFormsPage::DoToolBoxAction(): no parent node" );
531 xParentNode = pParentNode->m_xNode;
532 Reference< css::xml::dom::XNode > xNewNode;
533 if ( m_nAddElementId == _nToolBoxID )
537 pResId = RID_STR_DATANAV_ADD_ELEMENT;
538 xNewNode = m_xUIHelper->createElement( xParentNode, NEW_ELEMENT );
540 catch ( Exception const & )
542 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create element" );
545 else
547 pResId = RID_STR_DATANAV_ADD_ATTRIBUTE;
548 bIsElement = false;
549 eType = DITAttribute;
552 xNewNode = m_xUIHelper->createAttribute( xParentNode, NEW_ATTRIBUTE );
554 catch ( Exception const & )
556 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create attribute" );
562 xNewNode = xParentNode->appendChild( xNewNode );
564 catch ( Exception const & )
566 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while append child" );
571 Reference< css::xml::dom::XNode > xPNode;
572 if ( xNewNode.is() )
573 xPNode = xNewNode->getParentNode();
574 // attributes don't have parents in the DOM model
575 DBG_ASSERT( m_nAddAttributeId == _nToolBoxID
576 || xPNode.is(), "XFormsPage::DoToolboxAction(): node not added" );
578 catch ( Exception const & )
580 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" );
585 m_xUIHelper->getBindingForNode( xNewNode, true );
587 catch ( Exception const & )
589 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while get binding for node" );
591 pNode.reset(new ItemNode( xNewNode ));
593 else
597 pResId = RID_STR_DATANAV_ADD_BINDING;
598 xNewBinding = xModel->createBinding();
599 Reference< XSet > xBindings = xModel->getBindings();
600 xBindings->insert( makeAny( xNewBinding ) );
601 pNode.reset(new ItemNode( xNewBinding ));
602 eType = DITBinding;
604 catch ( Exception const & )
606 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolBoxAction(): exception while adding binding" );
610 AddDataItemDialog aDlg(GetFrameWeld(), pNode.get(), m_xUIHelper);
611 aDlg.set_title(SvxResId(pResId));
612 aDlg.InitText( eType );
613 short nReturn = aDlg.run();
614 if ( DGTInstance == m_eGroup )
616 if ( RET_OK == nReturn )
618 SvTreeListEntry* pNewEntry = AddEntry( std::move(pNode), bIsElement );
619 m_pItemList->MakeVisible( pNewEntry );
620 m_pItemList->Select( pNewEntry );
621 bIsDocModified = true;
623 else
627 Reference< css::xml::dom::XNode > xPNode;
628 Reference< css::xml::dom::XNode > xNode =
629 xParentNode->removeChild( pNode->m_xNode );
630 if ( xNode.is() )
631 xPNode = xNode->getParentNode();
632 DBG_ASSERT( !xPNode.is(), "XFormsPage::RemoveEntry(): node not removed" );
634 catch ( Exception const & )
636 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" );
640 else
642 if ( RET_OK == nReturn )
644 SvTreeListEntry* pNewEntry = AddEntry( xNewBinding );
645 m_pItemList->Select( pNewEntry );
646 bIsDocModified = true;
648 else
652 Reference< XSet > xBindings = xModel->getBindings();
653 xBindings->remove( makeAny( xNewBinding ) );
655 catch ( Exception const & )
657 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" );
663 else if(_nToolBoxID == m_nEditId)
665 bHandled = true;
666 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
667 if ( pEntry )
669 if ( DGTSubmission == m_eGroup && m_pItemList->GetParent( pEntry ) )
670 pEntry = m_pItemList->GetParent( pEntry );
671 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
672 if ( DGTInstance == m_eGroup || DGTBinding == m_eGroup )
674 if ( DGTInstance == m_eGroup && !m_sInstanceURL.isEmpty() )
676 LinkedInstanceWarningBox aMsgBox(GetFrameWeld());
677 if (aMsgBox.run() != RET_OK)
678 return bHandled;
681 AddDataItemDialog aDlg(GetFrameWeld(), pNode, m_xUIHelper);
682 DataItemType eType = DITElement;
683 const char* pResId = RID_STR_DATANAV_EDIT_ELEMENT;
684 if ( pNode && pNode->m_xNode.is() )
688 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
689 if ( eChildType == css::xml::dom::NodeType_ATTRIBUTE_NODE )
691 pResId = RID_STR_DATANAV_EDIT_ATTRIBUTE;
692 eType = DITAttribute;
695 catch ( Exception const & )
697 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" );
700 else if ( DGTBinding == m_eGroup )
702 pResId = RID_STR_DATANAV_EDIT_BINDING;
703 eType = DITBinding;
705 aDlg.set_title(SvxResId(pResId));
706 aDlg.InitText( eType );
707 if (aDlg.run() == RET_OK)
709 // Set the new name
710 OUString sNewName;
711 if ( DGTInstance == m_eGroup )
715 sNewName = m_xUIHelper->getNodeDisplayName(
716 pNode->m_xNode, m_pNaviWin->IsShowDetails() );
718 catch ( Exception const & )
720 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" );
723 else if (pNode)
727 OUString sTemp;
728 pNode->m_xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
729 sNewName += sTemp + ": ";
730 pNode->m_xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
731 sNewName += sTemp;
733 catch ( Exception const & )
735 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::DoToolboxAction()" );
739 m_pItemList->SetEntryText( pEntry, sNewName );
740 bIsDocModified = true;
743 else
745 AddSubmissionDialog aDlg(GetFrameWeld(), pNode, m_xUIHelper);
746 aDlg.set_title(SvxResId(RID_STR_DATANAV_EDIT_SUBMISSION));
747 if (aDlg.run() == RET_OK)
749 EditEntry( pNode->m_xPropSet );
750 bIsDocModified = true;
755 else if(_nToolBoxID == m_nRemoveId)
757 bHandled = true;
758 if ( DGTInstance == m_eGroup && !m_sInstanceURL.isEmpty() )
760 LinkedInstanceWarningBox aMsgBox(GetFrameWeld());
761 if (aMsgBox.run() != RET_OK)
762 return bHandled;
764 bIsDocModified = RemoveEntry();
766 else
768 OSL_FAIL( "XFormsPage::DoToolboxAction: unknown ID!" );
771 m_pNaviWin->DisableNotify( false );
772 EnableMenuItems( nullptr );
773 if ( bIsDocModified )
774 svxform::DataNavigatorWindow::SetDocModified();
775 return bHandled;
778 SvTreeListEntry* XFormsPage::AddEntry( std::unique_ptr<ItemNode> _pNewNode, bool _bIsElement )
780 SvTreeListEntry* pParent = m_pItemList->FirstSelected();
781 Image aImage(StockImage::Yes, _bIsElement ? OUString(RID_SVXBMP_ELEMENT) : OUString(RID_SVXBMP_ATTRIBUTE));
782 OUString sName;
785 sName = m_xUIHelper->getNodeDisplayName(
786 _pNewNode->m_xNode, m_pNaviWin->IsShowDetails() );
788 catch ( Exception& )
790 DBG_UNHANDLED_EXCEPTION("svx");
792 return m_pItemList->InsertEntry(
793 sName, aImage, aImage, pParent, false, TREELIST_APPEND, _pNewNode.release() );
796 SvTreeListEntry* XFormsPage::AddEntry( const Reference< XPropertySet >& _rEntry )
798 SvTreeListEntry* pEntry = nullptr;
799 Image aImage(StockImage::Yes, RID_SVXBMP_ELEMENT);
801 ItemNode* pNode = new ItemNode( _rEntry );
802 OUString sTemp;
804 if ( DGTSubmission == m_eGroup )
808 // ID
809 _rEntry->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
810 pEntry = m_pItemList->InsertEntry( sTemp, aImage, aImage, nullptr, false, TREELIST_APPEND, pNode );
811 // Action
812 _rEntry->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp;
813 OUString sEntry = SvxResId( RID_STR_DATANAV_SUBM_ACTION ) + sTemp;
814 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
815 // Method
816 _rEntry->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp;
817 sEntry = SvxResId( RID_STR_DATANAV_SUBM_METHOD ) +
818 m_aMethodString.toUI( sTemp );
819 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
820 // Ref
821 _rEntry->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp;
822 sEntry = SvxResId( RID_STR_DATANAV_SUBM_REF ) + sTemp;
823 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
824 // Bind
825 _rEntry->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp;
826 sEntry = SvxResId( RID_STR_DATANAV_SUBM_BIND ) + sTemp;
827 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
828 // Replace
829 _rEntry->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp;
830 sEntry = SvxResId( RID_STR_DATANAV_SUBM_REPLACE ) +
831 m_aReplaceString.toUI( sTemp );
832 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
834 catch ( Exception const & )
836 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::AddEntry(Ref)" );
839 else // then Binding Page
843 OUString sName;
844 _rEntry->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
845 sName += sTemp + ": ";
846 _rEntry->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
847 sName += sTemp;
848 pEntry = m_pItemList->InsertEntry(
849 sName, aImage, aImage, nullptr, false, TREELIST_APPEND, pNode );
851 catch ( Exception const & )
853 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::AddEntry(Ref)" );
857 return pEntry;
861 void XFormsPage::EditEntry( const Reference< XPropertySet >& _rEntry )
863 OUString sTemp;
865 if ( DGTSubmission == m_eGroup )
869 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
871 // #i36262# may be called for submission entry *or* for
872 // submission children. If we don't have any children, we
873 // assume the latter case and use the parent
874 if( m_pItemList->GetEntry( pEntry, 0 ) == nullptr )
876 pEntry = m_pItemList->GetModel()->GetParent( pEntry );
879 _rEntry->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
880 m_pItemList->SetEntryText( pEntry, sTemp );
882 _rEntry->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp;
883 OUString sEntry = SvxResId( RID_STR_DATANAV_SUBM_BIND ) + sTemp;
884 sal_uIntPtr nPos = 0;
885 SvTreeListEntry* pChild = m_pItemList->GetEntry( pEntry, nPos++ );
886 m_pItemList->SetEntryText( pChild, sEntry );
887 _rEntry->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp;
888 sEntry = SvxResId( RID_STR_DATANAV_SUBM_REF ) + sTemp;
889 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
890 m_pItemList->SetEntryText( pChild, sEntry );
891 _rEntry->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp;
892 sEntry = SvxResId( RID_STR_DATANAV_SUBM_ACTION ) + sTemp;
893 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
894 m_pItemList->SetEntryText( pChild, sEntry );
895 _rEntry->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp;
896 sEntry = SvxResId( RID_STR_DATANAV_SUBM_METHOD ) +
897 m_aMethodString.toUI( sTemp );
898 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
899 m_pItemList->SetEntryText( pChild, sEntry );
900 _rEntry->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp;
901 sEntry = SvxResId( RID_STR_DATANAV_SUBM_REPLACE ) +
902 m_aReplaceString.toUI( sTemp );
903 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
904 m_pItemList->SetEntryText( pChild, sEntry );
906 catch ( Exception const & )
908 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::EditEntry()" );
914 bool XFormsPage::RemoveEntry()
916 bool bRet = false;
917 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
918 if ( pEntry &&
919 ( DGTInstance != m_eGroup || m_pItemList->GetParent( pEntry ) ) )
921 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
922 DBG_ASSERT( xModel.is(), "XFormsPage::RemoveEntry(): no model" );
923 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
924 DBG_ASSERT( pNode, "XFormsPage::RemoveEntry(): no node" );
926 if ( DGTInstance == m_eGroup )
930 DBG_ASSERT( pNode->m_xNode.is(), "XFormsPage::RemoveEntry(): no XNode" );
931 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
932 bool bIsElement = ( eChildType == css::xml::dom::NodeType_ELEMENT_NODE );
933 const char* pResId = bIsElement ? RID_STR_QRY_REMOVE_ELEMENT : RID_STR_QRY_REMOVE_ATTRIBUTE;
934 OUString sVar = bIsElement ? OUString(ELEMENTNAME) : OUString(ATTRIBUTENAME);
935 std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(GetFrameWeld(),
936 VclMessageType::Question, VclButtonsType::YesNo,
937 SvxResId(pResId)));
938 OUString sMessText = xQBox->get_primary_text();
939 sMessText = sMessText.replaceFirst(
940 sVar, m_xUIHelper->getNodeDisplayName( pNode->m_xNode, false ) );
941 xQBox->set_primary_text(sMessText);
942 if (xQBox->run() == RET_YES)
944 SvTreeListEntry* pParent = m_pItemList->GetParent( pEntry );
945 DBG_ASSERT( pParent, "XFormsPage::RemoveEntry(): no parent entry" );
946 ItemNode* pParentNode = static_cast< ItemNode* >( pParent->GetUserData() );
947 DBG_ASSERT( pParentNode && pParentNode->m_xNode.is(), "XFormsPage::RemoveEntry(): no parent XNode" );
949 Reference< css::xml::dom::XNode > xPNode;
950 Reference< css::xml::dom::XNode > xNode =
951 pParentNode->m_xNode->removeChild( pNode->m_xNode );
952 if ( xNode.is() )
953 xPNode = xNode->getParentNode();
954 DBG_ASSERT( !xPNode.is(), "XFormsPage::RemoveEntry(): node not removed" );
955 bRet = true;
958 catch ( Exception const & )
960 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::RemoveEntry()" );
963 else
965 DBG_ASSERT( pNode->m_xPropSet.is(), "XFormsPage::RemoveEntry(): no propset" );
966 bool bSubmission = ( DGTSubmission == m_eGroup );
967 const char* pResId = bSubmission ? RID_STR_QRY_REMOVE_SUBMISSION : RID_STR_QRY_REMOVE_BINDING;
968 OUString sProperty = bSubmission ? OUString(PN_SUBMISSION_ID) : OUString(PN_BINDING_ID);
969 OUString sSearch = bSubmission ? OUString(SUBMISSIONNAME) : OUString(BINDINGNAME);
970 OUString sName;
973 pNode->m_xPropSet->getPropertyValue( sProperty ) >>= sName;
975 catch ( Exception const & )
977 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::RemoveEntry()" );
979 std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(GetFrameWeld(),
980 VclMessageType::Question, VclButtonsType::YesNo,
981 SvxResId(pResId)));
982 OUString sMessText = xQBox->get_primary_text();
983 sMessText = sMessText.replaceFirst( sSearch, sName);
984 xQBox->set_primary_text(sMessText);
985 if (xQBox->run() == RET_YES)
989 if ( bSubmission )
990 xModel->getSubmissions()->remove( makeAny( pNode->m_xPropSet ) );
991 else // then Binding Page
992 xModel->getBindings()->remove( makeAny( pNode->m_xPropSet ) );
993 bRet = true;
995 catch ( Exception const & )
997 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::RemoveEntry()" );
1002 if ( bRet )
1003 m_pItemList->RemoveEntry( pEntry );
1006 return bRet;
1010 bool XFormsPage::EventNotify( NotifyEvent& rNEvt )
1012 bool bHandled = false;
1014 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
1016 sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
1018 switch ( nCode )
1020 case KEY_DELETE:
1021 bHandled = DoMenuAction( m_nRemoveId );
1022 break;
1026 return bHandled || Window::EventNotify( rNEvt );
1029 void XFormsPage::Resize()
1031 Size aSize = GetOutputSizePixel();
1032 Size aTbxSize = m_pToolBox->GetSizePixel();
1033 aTbxSize.setWidth( aSize.Width() );
1034 m_pToolBox->SetSizePixel( aTbxSize );
1035 aSize.AdjustWidth( -4 );
1036 aSize.AdjustHeight( -( 4 + aTbxSize.Height() ) );
1037 m_pItemList->SetPosSizePixel( Point( 2, 2 + aTbxSize.Height() ), aSize );
1040 OUString XFormsPage::SetModel( const Reference< css::xforms::XModel >& _xModel, sal_uInt16 _nPagePos )
1042 DBG_ASSERT( _xModel.is(), "XFormsPage::SetModel(): invalid model" );
1044 m_xUIHelper.set( _xModel, UNO_QUERY );
1045 OUString sRet;
1046 m_bHasModel = true;
1048 switch ( m_eGroup )
1050 case DGTInstance :
1052 DBG_ASSERT( _nPagePos != TAB_PAGE_NOTFOUND, "XFormsPage::SetModel(): invalid page position" );
1055 Reference< XContainer > xContainer( _xModel->getInstances(), UNO_QUERY );
1056 if ( xContainer.is() )
1057 m_pNaviWin->AddContainerBroadcaster( xContainer );
1059 Reference< XEnumerationAccess > xNumAccess = _xModel->getInstances();
1060 if ( xNumAccess.is() )
1062 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1063 if ( xNum.is() && xNum->hasMoreElements() )
1065 sal_uInt16 nIter = 0;
1066 while ( xNum->hasMoreElements() )
1068 if ( nIter == _nPagePos )
1070 Sequence< PropertyValue > xPropSeq;
1071 Any aAny = xNum->nextElement();
1072 if ( aAny >>= xPropSeq )
1073 sRet = LoadInstance(xPropSeq);
1074 else
1076 SAL_WARN( "svx.form", "XFormsPage::SetModel(): invalid instance" );
1078 break;
1080 else
1082 xNum->nextElement();
1083 ++nIter;
1089 catch( Exception const & )
1091 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::SetModel()" );
1093 break;
1096 case DGTSubmission :
1098 DBG_ASSERT( TAB_PAGE_NOTFOUND == _nPagePos, "XFormsPage::SetModel(): invalid page position" );
1101 Reference< XContainer > xContainer( _xModel->getSubmissions(), UNO_QUERY );
1102 if ( xContainer.is() )
1103 m_pNaviWin->AddContainerBroadcaster( xContainer );
1105 Reference< XEnumerationAccess > xNumAccess = _xModel->getSubmissions();
1106 if ( xNumAccess.is() )
1108 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1109 if ( xNum.is() && xNum->hasMoreElements() )
1111 while ( xNum->hasMoreElements() )
1113 Reference< XPropertySet > xPropSet;
1114 Any aAny = xNum->nextElement();
1115 if ( aAny >>= xPropSet )
1116 AddEntry( xPropSet );
1121 catch( Exception const & )
1123 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::SetModel()" );
1125 break;
1128 case DGTBinding :
1130 DBG_ASSERT( TAB_PAGE_NOTFOUND == _nPagePos, "XFormsPage::SetModel(): invalid page position" );
1133 Reference< XContainer > xContainer( _xModel->getBindings(), UNO_QUERY );
1134 if ( xContainer.is() )
1135 m_pNaviWin->AddContainerBroadcaster( xContainer );
1137 Reference< XEnumerationAccess > xNumAccess = _xModel->getBindings();
1138 if ( xNumAccess.is() )
1140 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1141 if ( xNum.is() && xNum->hasMoreElements() )
1143 Image aImage(StockImage::Yes, RID_SVXBMP_ELEMENT);
1144 while ( xNum->hasMoreElements() )
1146 Reference< XPropertySet > xPropSet;
1147 Any aAny = xNum->nextElement();
1148 if ( aAny >>= xPropSet )
1150 OUString sEntry;
1151 OUString sTemp;
1152 xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
1153 sEntry += sTemp + ": ";
1154 xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
1155 sEntry += sTemp;
1157 ItemNode* pNode = new ItemNode( xPropSet );
1158 m_pItemList->InsertEntry(
1159 sEntry, aImage, aImage, nullptr, false, TREELIST_APPEND, pNode );
1165 catch( Exception const & )
1167 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::SetModel()" );
1169 break;
1171 default:
1172 OSL_FAIL( "XFormsPage::SetModel: unknown group!" );
1173 break;
1176 EnableMenuItems( nullptr );
1178 return sRet;
1181 void XFormsPage::ClearModel()
1183 m_bHasModel = false;
1184 m_pItemList->DeleteAndClear();
1187 OUString XFormsPage::LoadInstance(const Sequence< PropertyValue >& _xPropSeq)
1189 OUString sRet;
1190 OUString sTemp;
1191 OUString sInstModel = PN_INSTANCE_MODEL;
1192 OUString sInstName = PN_INSTANCE_ID;
1193 OUString sInstURL = PN_INSTANCE_URL;
1194 for ( const PropertyValue& rProp : _xPropSeq )
1196 if ( sInstModel == rProp.Name )
1198 Reference< css::xml::dom::XNode > xRoot;
1199 if ( rProp.Value >>= xRoot )
1203 Reference< XEventTarget > xTarget( xRoot, UNO_QUERY );
1204 if ( xTarget.is() )
1205 m_pNaviWin->AddEventBroadcaster( xTarget );
1207 OUString sNodeName =
1208 m_xUIHelper->getNodeDisplayName( xRoot, m_pNaviWin->IsShowDetails() );
1209 if ( sNodeName.isEmpty() )
1210 sNodeName = xRoot->getNodeName();
1211 if ( xRoot->hasChildNodes() )
1212 AddChildren(nullptr, xRoot);
1214 catch ( Exception const & )
1216 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::LoadInstance()" );
1220 else if ( sInstName == rProp.Name && ( rProp.Value >>= sTemp ) )
1221 m_sInstanceName = sRet = sTemp;
1222 else if ( sInstURL == rProp.Name && ( rProp.Value >>= sTemp ) )
1223 m_sInstanceURL = sTemp;
1226 return sRet;
1230 bool XFormsPage::DoMenuAction( sal_uInt16 _nMenuID )
1232 return DoToolBoxAction( _nMenuID );
1236 void XFormsPage::EnableMenuItems( Menu* _pMenu )
1238 bool bEnableAdd = false;
1239 bool bEnableEdit = false;
1240 bool bEnableRemove = false;
1242 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
1243 if ( pEntry )
1245 bEnableAdd = true;
1246 bool bSubmitChild = false;
1247 if ( DGTSubmission == m_eGroup && m_pItemList->GetParent( pEntry ) )
1249 pEntry = m_pItemList->GetParent( pEntry );
1250 bSubmitChild = true;
1252 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
1253 if ( pNode && ( pNode->m_xNode.is() || pNode->m_xPropSet.is() ) )
1255 bEnableEdit = true;
1256 bEnableRemove = !bSubmitChild;
1257 if ( DGTInstance == m_eGroup && !m_pItemList->GetParent( pEntry ) )
1258 bEnableRemove = false;
1259 if ( pNode->m_xNode.is() )
1263 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
1264 if ( eChildType != css::xml::dom::NodeType_ELEMENT_NODE
1265 && eChildType != css::xml::dom::NodeType_DOCUMENT_NODE )
1267 bEnableAdd = false;
1270 catch ( Exception const & )
1272 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::EnableMenuItems()" );
1277 else if ( m_eGroup != DGTInstance )
1278 bEnableAdd = true;
1280 m_pToolBox->EnableItem( m_nAddId, bEnableAdd );
1281 m_pToolBox->EnableItem( m_nAddElementId, bEnableAdd );
1282 m_pToolBox->EnableItem( m_nAddAttributeId, bEnableAdd );
1283 m_pToolBox->EnableItem( m_nEditId, bEnableEdit );
1284 m_pToolBox->EnableItem( m_nRemoveId, bEnableRemove );
1286 if ( _pMenu )
1288 _pMenu->EnableItem(_pMenu->GetItemId("additem"), bEnableAdd);
1289 _pMenu->EnableItem(_pMenu->GetItemId("addelement"), bEnableAdd);
1290 _pMenu->EnableItem(_pMenu->GetItemId("addattribute"), bEnableAdd);
1291 _pMenu->EnableItem(_pMenu->GetItemId("edit"), bEnableEdit);
1292 _pMenu->EnableItem(_pMenu->GetItemId("delete"), bEnableRemove);
1294 if ( DGTInstance == m_eGroup )
1296 const char* pResId1 = RID_STR_DATANAV_EDIT_ELEMENT;
1297 const char* pResId2 = RID_STR_DATANAV_REMOVE_ELEMENT;
1298 if ( pEntry )
1300 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
1301 if ( pNode && pNode->m_xNode.is() )
1305 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
1306 if ( eChildType == css::xml::dom::NodeType_ATTRIBUTE_NODE )
1308 pResId1 = RID_STR_DATANAV_EDIT_ATTRIBUTE;
1309 pResId2 = RID_STR_DATANAV_REMOVE_ATTRIBUTE;
1312 catch ( Exception const & )
1314 TOOLS_WARN_EXCEPTION( "svx.form", "XFormsPage::EnableMenuItems()" );
1318 m_pToolBox->SetItemText( m_nEditId, SvxResId( pResId1 ) );
1319 m_pToolBox->SetItemText( m_nRemoveId, SvxResId( pResId2 ) );
1320 if ( _pMenu )
1322 _pMenu->SetItemText(_pMenu->GetItemId("edit"), SvxResId( pResId1 ) );
1323 _pMenu->SetItemText(_pMenu->GetItemId("delete"), SvxResId( pResId2 ) );
1328 DataNavigatorWindow::DataNavigatorWindow(vcl::Window* pParent, SfxBindings const * pBindings)
1329 : Window(pParent)
1330 , m_pInstPage(nullptr)
1331 , m_pSubmissionPage(nullptr)
1332 , m_pBindingPage(nullptr)
1333 , m_nLastSelectedPos(LISTBOX_ENTRY_NOTFOUND)
1334 , m_bShowDetails(false)
1335 , m_bIsNotifyDisabled(false)
1336 , m_xDataListener(new DataListener(this))
1338 m_pUIBuilder.reset(new VclBuilder(this, getUIRootDir(), "svx/ui/datanavigator.ui", "DataNavigator"));
1339 get(m_pModelsBox, "modelslist");
1340 get(m_pModelBtn, "modelsbutton");
1341 get(m_pTabCtrl, "tabcontrol");
1342 get(m_pInstanceBtn, "instances");
1344 // handler
1345 m_pModelsBox->SetSelectHdl( LINK( this, DataNavigatorWindow, ModelSelectListBoxHdl ) );
1346 Link<MenuButton *, void> aLink1 = LINK( this, DataNavigatorWindow, MenuSelectHdl );
1347 m_pModelBtn->SetSelectHdl( aLink1 );
1348 m_pInstanceBtn->SetSelectHdl( aLink1 );
1349 Link<MenuButton*,void> aLink2 = LINK( this, DataNavigatorWindow, MenuActivateHdl );
1350 m_pModelBtn->SetActivateHdl( aLink2 );
1351 m_pInstanceBtn->SetActivateHdl( aLink2 );
1352 m_pTabCtrl->SetActivatePageHdl( LINK( this, DataNavigatorWindow, ActivatePageHdl ) );
1353 m_aUpdateTimer.SetTimeout( 2000 );
1354 m_aUpdateTimer.SetInvokeHandler( LINK( this, DataNavigatorWindow, UpdateHdl ) );
1356 // init tabcontrol
1357 m_pTabCtrl->Show();
1358 OString sPageId("instance");
1359 SvtViewOptions aViewOpt( EViewType::TabDialog, CFGNAME_DATANAVIGATOR );
1360 if ( aViewOpt.Exists() )
1362 sPageId = aViewOpt.GetPageID();
1363 aViewOpt.GetUserItem(CFGNAME_SHOWDETAILS) >>= m_bShowDetails;
1366 Menu* pMenu = m_pInstanceBtn->GetPopupMenu();
1367 sal_uInt16 nInstancesDetailsId = pMenu->GetItemId("instancesdetails");
1368 pMenu->SetItemBits(nInstancesDetailsId, MenuItemBits::CHECKABLE );
1369 pMenu->CheckItem(nInstancesDetailsId, m_bShowDetails );
1371 m_pTabCtrl->SetCurPageId(m_pTabCtrl->GetPageId(sPageId));
1372 ActivatePageHdl(m_pTabCtrl);
1374 // get our frame
1375 DBG_ASSERT( pBindings != nullptr,
1376 "DataNavigatorWindow::LoadModels(): no SfxBindings; can't get frame" );
1377 m_xFrame = pBindings->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface();
1378 DBG_ASSERT( m_xFrame.is(), "DataNavigatorWindow::LoadModels(): no frame" );
1379 // add frameaction listener
1380 Reference< XFrameActionListener > xListener(
1381 static_cast< XFrameActionListener* >( m_xDataListener.get() ), UNO_QUERY );
1382 m_xFrame->addFrameActionListener( xListener );
1384 // load xforms models of the current document
1385 LoadModels();
1388 DataNavigatorWindow::~DataNavigatorWindow()
1390 disposeOnce();
1393 void DataNavigatorWindow::dispose()
1395 SvtViewOptions aViewOpt( EViewType::TabDialog, CFGNAME_DATANAVIGATOR );
1396 aViewOpt.SetPageID(m_pTabCtrl->GetPageName(m_pTabCtrl->GetCurPageId()));
1397 aViewOpt.SetUserItem(CFGNAME_SHOWDETAILS, Any(m_bShowDetails));
1399 m_pInstPage.disposeAndClear();
1400 m_pSubmissionPage.disposeAndClear();
1401 m_pBindingPage.disposeAndClear();
1403 sal_Int32 i, nCount = m_aPageList.size();
1404 for ( i = 0; i < nCount; ++i )
1405 m_aPageList[i].disposeAndClear();
1406 m_aPageList.clear();
1408 Reference< XFrameActionListener > xListener(
1409 static_cast< XFrameActionListener* >( m_xDataListener.get() ), UNO_QUERY );
1410 m_xFrame->removeFrameActionListener( xListener );
1411 RemoveBroadcaster();
1412 m_xDataListener.clear();
1413 disposeBuilder();
1414 m_pModelsBox.clear();
1415 m_pModelBtn.clear();
1416 m_pTabCtrl.clear();
1417 m_pInstanceBtn.clear();
1418 vcl::Window::dispose();
1422 IMPL_LINK( DataNavigatorWindow, ModelSelectListBoxHdl, ListBox&, rBox, void )
1424 ModelSelectHdl(&rBox);
1426 void DataNavigatorWindow::ModelSelectHdl(ListBox const * pBox)
1428 sal_Int32 nPos = m_pModelsBox->GetSelectedEntryPos();
1429 // pBox == NULL, if you want to force a new fill.
1430 if ( nPos != m_nLastSelectedPos || !pBox )
1432 m_nLastSelectedPos = nPos;
1433 ClearAllPageModels( pBox != nullptr );
1434 InitPages();
1435 SetPageModel();
1439 IMPL_LINK( DataNavigatorWindow, MenuSelectHdl, MenuButton *, pBtn, void )
1441 bool bIsDocModified = false;
1442 Reference< css::xforms::XFormsUIHelper1 > xUIHelper;
1443 sal_Int32 nSelectedPos = m_pModelsBox->GetSelectedEntryPos();
1444 OUString sSelectedModel( m_pModelsBox->GetEntry( nSelectedPos ) );
1445 Reference< css::xforms::XModel > xModel;
1448 Any aAny = m_xDataContainer->getByName( sSelectedModel );
1449 if ( aAny >>= xModel )
1450 xUIHelper.set( xModel, UNO_QUERY );
1452 catch ( Exception const & )
1454 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" );
1456 DBG_ASSERT( xUIHelper.is(), "DataNavigatorWindow::MenuSelectHdl(): no UIHelper" );
1458 m_bIsNotifyDisabled = true;
1460 if (m_pModelBtn == pBtn)
1462 OString sIdent(pBtn->GetCurItemIdent());
1463 if (sIdent == "modelsadd")
1465 AddModelDialog aDlg(GetFrameWeld(), false);
1466 bool bShowDialog = true;
1467 while ( bShowDialog )
1469 bShowDialog = false;
1470 if (aDlg.run() == RET_OK)
1472 OUString sNewName = aDlg.GetName();
1473 bool bDocumentData = aDlg.GetModifyDoc();
1475 if ( m_pModelsBox->GetEntryPos( sNewName ) != LISTBOX_ENTRY_NOTFOUND )
1477 // error: model name already exists
1478 std::unique_ptr<weld::MessageDialog> xErrBox(Application::CreateMessageDialog(GetFrameWeld(),
1479 VclMessageType::Warning, VclButtonsType::Ok,
1480 SvxResId(RID_STR_DOUBLE_MODELNAME)));
1481 xErrBox->set_primary_text(xErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sNewName));
1482 xErrBox->run();
1483 bShowDialog = true;
1485 else
1489 // add new model to frame model
1490 Reference< css::xforms::XModel > xNewModel(
1491 xUIHelper->newModel( m_xFrameModel, sNewName ), UNO_SET_THROW );
1493 Reference< XPropertySet > xModelProps( xNewModel, UNO_QUERY_THROW );
1494 xModelProps->setPropertyValue("ExternalData", makeAny( !bDocumentData ) );
1496 sal_Int32 nNewPos = m_pModelsBox->InsertEntry( sNewName );
1497 m_pModelsBox->SelectEntryPos( nNewPos );
1498 ModelSelectHdl(m_pModelsBox);
1499 bIsDocModified = true;
1501 catch ( Exception const & )
1503 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" );
1509 else if (sIdent == "modelsedit")
1511 AddModelDialog aDlg(GetFrameWeld(), true);
1512 aDlg.SetName( sSelectedModel );
1514 bool bDocumentData( false );
1517 Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY_THROW );
1518 Reference< XNameContainer > xXForms( xFormsSupp->getXForms(), UNO_SET_THROW );
1519 Reference< XPropertySet > xModelProps( xXForms->getByName( sSelectedModel ), UNO_QUERY_THROW );
1520 bool bExternalData = false;
1521 OSL_VERIFY( xModelProps->getPropertyValue( "ExternalData" ) >>= bExternalData );
1522 bDocumentData = !bExternalData;
1524 catch( const Exception& )
1526 DBG_UNHANDLED_EXCEPTION("svx");
1528 aDlg.SetModifyDoc( bDocumentData );
1530 if (aDlg.run() == RET_OK)
1532 if ( aDlg.GetModifyDoc() != bDocumentData )
1534 bDocumentData = aDlg.GetModifyDoc();
1537 Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY_THROW );
1538 Reference< XNameContainer > xXForms( xFormsSupp->getXForms(), UNO_SET_THROW );
1539 Reference< XPropertySet > xModelProps( xXForms->getByName( sSelectedModel ), UNO_QUERY_THROW );
1540 xModelProps->setPropertyValue( "ExternalData", makeAny( !bDocumentData ) );
1541 bIsDocModified = true;
1543 catch( const Exception& )
1545 DBG_UNHANDLED_EXCEPTION("svx");
1549 OUString sNewName = aDlg.GetName();
1550 if ( !sNewName.isEmpty() && ( sNewName != sSelectedModel ) )
1554 xUIHelper->renameModel( m_xFrameModel, sSelectedModel, sNewName );
1556 m_pModelsBox->RemoveEntry( nSelectedPos );
1557 nSelectedPos = m_pModelsBox->InsertEntry( sNewName );
1558 m_pModelsBox->SelectEntryPos( nSelectedPos );
1559 bIsDocModified = true;
1561 catch ( Exception const & )
1563 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" );
1568 else if (sIdent == "modelsremove")
1570 std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(GetFrameWeld(),
1571 VclMessageType::Question, VclButtonsType::YesNo,
1572 SvxResId( RID_STR_QRY_REMOVE_MODEL)));
1573 OUString sText = xQBox->get_primary_text();
1574 sText = sText.replaceFirst( MODELNAME, sSelectedModel );
1575 xQBox->set_primary_text(sText);
1576 if (xQBox->run() == RET_YES)
1580 xUIHelper->removeModel( m_xFrameModel, sSelectedModel );
1582 catch ( Exception const & )
1584 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" );
1586 m_pModelsBox->RemoveEntry( nSelectedPos );
1587 if ( m_pModelsBox->GetEntryCount() <= nSelectedPos )
1588 nSelectedPos = m_pModelsBox->GetEntryCount() - 1;
1589 m_pModelsBox->SelectEntryPos( nSelectedPos );
1590 ModelSelectHdl(m_pModelsBox);
1591 bIsDocModified = true;
1594 else
1596 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong menu item" );
1599 else if (m_pInstanceBtn == pBtn)
1601 OString sIdent(pBtn->GetCurItemIdent());
1602 if (sIdent == "instancesadd")
1604 AddInstanceDialog aDlg(GetFrameWeld(), false);
1605 if (aDlg.run() == RET_OK)
1607 sal_uInt16 nInst = GetNewPageId();
1608 OUString sName = aDlg.GetName();
1609 OUString sURL = aDlg.GetURL();
1610 bool bLinkOnce = aDlg.IsLinkInstance();
1613 xUIHelper->newInstance( sName, sURL, !bLinkOnce );
1615 catch ( Exception const & )
1617 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" );
1619 ModelSelectHdl( nullptr );
1620 m_pTabCtrl->SetCurPageId( nInst );
1621 XFormsPage* pPage = GetCurrentPage( nInst );
1622 pPage->SetInstanceName(sName);
1623 pPage->SetInstanceURL(sURL);
1624 pPage->SetLinkOnce(bLinkOnce);
1625 ActivatePageHdl(m_pTabCtrl);
1626 bIsDocModified = true;
1629 else if (sIdent == "instancesedit")
1631 sal_uInt16 nId = 0;
1632 XFormsPage* pPage = GetCurrentPage( nId );
1633 if ( pPage )
1635 AddInstanceDialog aDlg(GetFrameWeld(), true);
1636 aDlg.SetName( pPage->GetInstanceName() );
1637 aDlg.SetURL( pPage->GetInstanceURL() );
1638 aDlg.SetLinkInstance( pPage->GetLinkOnce() );
1639 OUString sOldName = aDlg.GetName();
1640 if (aDlg.run() == RET_OK)
1642 OUString sNewName = aDlg.GetName();
1643 OUString sURL = aDlg.GetURL();
1644 bool bLinkOnce = aDlg.IsLinkInstance();
1647 xUIHelper->renameInstance( sOldName,
1648 sNewName,
1649 sURL,
1650 !bLinkOnce );
1652 catch ( Exception const & )
1654 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" );
1656 pPage->SetInstanceName(sNewName);
1657 pPage->SetInstanceURL(sURL);
1658 pPage->SetLinkOnce(bLinkOnce);
1659 m_pTabCtrl->SetPageText( nId, sNewName );
1660 bIsDocModified = true;
1664 else if (sIdent == "instancesremove")
1666 sal_uInt16 nId = 0;
1667 VclPtr<XFormsPage> pPage = GetCurrentPage( nId );
1668 if ( pPage )
1670 OUString sInstName = pPage->GetInstanceName();
1671 std::unique_ptr<weld::MessageDialog> xQBox(Application::CreateMessageDialog(GetFrameWeld(),
1672 VclMessageType::Question, VclButtonsType::YesNo,
1673 SvxResId(RID_STR_QRY_REMOVE_INSTANCE)));
1674 OUString sMessText = xQBox->get_primary_text();
1675 sMessText = sMessText.replaceFirst( INSTANCENAME, sInstName );
1676 xQBox->set_primary_text(sMessText);
1677 if (xQBox->run() == RET_YES)
1679 bool bDoRemove = false;
1680 if (IsAdditionalPage(nId))
1682 auto aPageListEnd = m_aPageList.end();
1683 auto aFoundPage = std::find( m_aPageList.begin(), aPageListEnd, pPage );
1684 if ( aFoundPage != aPageListEnd )
1686 m_aPageList.erase( aFoundPage );
1687 pPage.disposeAndClear() ;
1688 bDoRemove = true;
1691 else
1693 m_pInstPage.disposeAndClear();
1694 bDoRemove = true;
1697 if ( bDoRemove )
1701 xUIHelper->removeInstance( sInstName );
1703 catch (const Exception&)
1705 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::MenuSelectHdl()" );
1707 m_pTabCtrl->RemovePage( nId );
1708 m_pTabCtrl->SetCurPageId(m_pTabCtrl->GetPageId("instance"));
1709 ModelSelectHdl( nullptr );
1710 bIsDocModified = true;
1715 else if (sIdent == "instancesdetails")
1717 m_bShowDetails = !m_bShowDetails;
1718 PopupMenu* pMenu = m_pInstanceBtn->GetPopupMenu();
1719 pMenu->CheckItem("instancesdetails", m_bShowDetails );
1720 ModelSelectHdl(m_pModelsBox);
1722 else
1724 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong menu item" );
1727 else
1729 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong button" );
1732 m_bIsNotifyDisabled = false;
1734 if ( bIsDocModified )
1735 SetDocModified();
1738 bool DataNavigatorWindow::IsAdditionalPage(sal_uInt16 nId) const
1740 return m_pTabCtrl->GetPageName(nId).isEmpty();
1743 IMPL_LINK( DataNavigatorWindow, MenuActivateHdl, MenuButton *, pBtn, void )
1745 Menu* pMenu = pBtn->GetPopupMenu();
1747 if (m_pInstanceBtn == pBtn)
1749 sal_uInt16 nId(m_pTabCtrl->GetCurPageId());
1750 bool bIsInstPage = (IsAdditionalPage(nId) || m_pTabCtrl->GetPageName(nId) == "instance");
1751 pMenu->EnableItem( "instancesedit", bIsInstPage );
1752 pMenu->EnableItem( "instancesremove",
1753 bIsInstPage && m_pTabCtrl->GetPageCount() > MIN_PAGE_COUNT );
1754 pMenu->EnableItem( "instancesdetails", bIsInstPage );
1756 else if (m_pModelBtn == pBtn)
1758 // we need at least one model!
1759 pMenu->EnableItem("modelsremove", m_pModelsBox->GetEntryCount() > 1 );
1761 else
1763 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuActivateHdl(): wrong button" );
1767 IMPL_LINK_NOARG(DataNavigatorWindow, ActivatePageHdl, TabControl*, void)
1769 sal_uInt16 nId = 0;
1770 XFormsPage* pPage = GetCurrentPage( nId );
1771 if ( pPage )
1773 m_pTabCtrl->SetTabPage( nId, pPage );
1774 if ( m_xDataContainer.is() && !pPage->HasModel() )
1775 SetPageModel();
1779 IMPL_LINK_NOARG(DataNavigatorWindow, UpdateHdl, Timer *, void)
1781 ModelSelectHdl( nullptr );
1784 XFormsPage* DataNavigatorWindow::GetCurrentPage( sal_uInt16& rCurId )
1786 rCurId = m_pTabCtrl->GetCurPageId();
1787 VclPtr<XFormsPage> pPage;
1788 OString sName(m_pTabCtrl->GetPageName(rCurId));
1789 if (sName == "submissions")
1791 if ( !m_pSubmissionPage )
1792 m_pSubmissionPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTSubmission);
1793 pPage = m_pSubmissionPage;
1795 else if (sName == "bindings")
1797 if ( !m_pBindingPage )
1798 m_pBindingPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTBinding);
1799 pPage = m_pBindingPage;
1801 else if (sName == "instance")
1803 if ( !m_pInstPage )
1804 m_pInstPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTInstance);
1805 pPage = m_pInstPage;
1807 else
1809 sal_uInt16 nPos = m_pTabCtrl->GetPagePos( rCurId );
1810 if ( HasFirstInstancePage() && nPos > 0 )
1811 nPos--;
1812 if ( m_aPageList.size() > nPos )
1813 pPage = m_aPageList[nPos];
1814 else
1816 pPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTInstance);
1817 m_aPageList.push_back( pPage );
1821 return pPage;
1824 void DataNavigatorWindow::LoadModels()
1826 if ( !m_xFrameModel.is() )
1828 // get model of active frame
1829 Reference< XController > xCtrl = m_xFrame->getController();
1830 if ( xCtrl.is() )
1834 m_xFrameModel = xCtrl->getModel();
1836 catch ( Exception const & )
1838 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::LoadModels()" );
1843 if ( m_xFrameModel.is() )
1847 Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY );
1848 if ( xFormsSupp.is() )
1850 Reference< XNameContainer > xContainer = xFormsSupp->getXForms();
1851 if ( xContainer.is() )
1853 m_xDataContainer = xContainer;
1854 const Sequence< OUString > aNameList = m_xDataContainer->getElementNames();
1855 for ( const OUString& rName : aNameList )
1857 Any aAny = m_xDataContainer->getByName( rName );
1858 Reference< css::xforms::XModel > xFormsModel;
1859 if ( aAny >>= xFormsModel )
1860 m_pModelsBox->InsertEntry( xFormsModel->getID() );
1865 catch( Exception const & )
1867 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::LoadModels()" );
1871 if ( m_pModelsBox->GetEntryCount() > 0 )
1873 m_pModelsBox->SelectEntryPos(0);
1874 ModelSelectHdl(m_pModelsBox);
1878 void DataNavigatorWindow::SetPageModel()
1880 OUString sModel( m_pModelsBox->GetSelectedEntry() );
1883 Any aAny = m_xDataContainer->getByName( sModel );
1884 Reference< css::xforms::XModel > xFormsModel;
1885 if ( aAny >>= xFormsModel )
1887 sal_uInt16 nPagePos = TAB_PAGE_NOTFOUND;
1888 sal_uInt16 nId = 0;
1889 XFormsPage* pPage = GetCurrentPage( nId );
1890 DBG_ASSERT( pPage, "DataNavigatorWindow::SetPageModel(): no page" );
1891 if (IsAdditionalPage(nId) || m_pTabCtrl->GetPageName(nId) == "instance")
1893 // instance page
1894 nPagePos = m_pTabCtrl->GetPagePos( nId );
1896 m_bIsNotifyDisabled = true;
1897 OUString sText = pPage->SetModel( xFormsModel, nPagePos );
1898 m_bIsNotifyDisabled = false;
1899 if ( !sText.isEmpty() )
1900 m_pTabCtrl->SetPageText( nId, sText );
1903 catch (const NoSuchElementException& )
1905 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" );
1907 catch( Exception const & )
1909 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::SetPageModel()" );
1913 void DataNavigatorWindow::InitPages()
1915 OUString sModel( m_pModelsBox->GetSelectedEntry() );
1918 Any aAny = m_xDataContainer->getByName( sModel );
1919 Reference< css::xforms::XModel > xModel;
1920 if ( aAny >>= xModel )
1922 Reference< XEnumerationAccess > xNumAccess = xModel->getInstances();
1923 if ( xNumAccess.is() )
1925 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1926 if ( xNum.is() && xNum->hasMoreElements() )
1928 sal_Int32 nAlreadyLoadedCount = m_aPageList.size();
1929 if ( !HasFirstInstancePage() && nAlreadyLoadedCount > 0 )
1930 nAlreadyLoadedCount--;
1931 sal_Int32 nIdx = 0;
1932 while ( xNum->hasMoreElements() )
1934 if ( nIdx > nAlreadyLoadedCount )
1936 Sequence< PropertyValue > xPropSeq;
1937 if ( xNum->nextElement() >>= xPropSeq )
1938 CreateInstancePage( xPropSeq );
1939 else
1941 SAL_WARN( "svx.form", "DataNavigator::InitPages(): invalid instance" );
1944 else
1945 xNum->nextElement();
1946 nIdx++;
1952 catch ( NoSuchElementException& )
1954 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" );
1956 catch( Exception const & )
1958 TOOLS_WARN_EXCEPTION( "svx.form", "DataNavigatorWindow::SetPageModel()" );
1962 void DataNavigatorWindow::ClearAllPageModels( bool bClearPages )
1964 if ( m_pInstPage )
1965 m_pInstPage->ClearModel();
1966 if ( m_pSubmissionPage )
1967 m_pSubmissionPage->ClearModel();
1968 if ( m_pBindingPage )
1969 m_pBindingPage->ClearModel();
1971 sal_Int32 i, nCount = m_aPageList.size();
1972 for ( i = 0; i < nCount; ++i )
1974 VclPtr<XFormsPage> pPage = m_aPageList[i];
1975 pPage->ClearModel();
1976 if ( bClearPages )
1977 pPage.disposeAndClear();
1980 if ( bClearPages )
1982 m_aPageList.clear();
1983 while ( m_pTabCtrl->GetPageCount() > MIN_PAGE_COUNT )
1984 m_pTabCtrl->RemovePage( m_pTabCtrl->GetPageId( 1 ) );
1988 void DataNavigatorWindow::CreateInstancePage( const Sequence< PropertyValue >& _xPropSeq )
1990 OUString sInstName;
1991 auto pProp = std::find_if(_xPropSeq.begin(), _xPropSeq.end(),
1992 [](const PropertyValue& rProp) { return PN_INSTANCE_ID == rProp.Name; });
1993 if (pProp != _xPropSeq.end())
1994 pProp->Value >>= sInstName;
1996 sal_uInt16 nPageId = GetNewPageId();
1997 if ( sInstName.isEmpty() )
1999 SAL_WARN( "svx.form", "DataNavigatorWindow::CreateInstancePage(): instance without name" );
2000 sInstName = "untitled" + OUString::number( nPageId );
2002 m_pTabCtrl->InsertPage( nPageId, sInstName, m_pTabCtrl->GetPageCount() - 2 );
2005 bool DataNavigatorWindow::HasFirstInstancePage() const
2007 return (m_pTabCtrl->GetPageName(m_pTabCtrl->GetPageId(0)) == "instance");
2010 sal_uInt16 DataNavigatorWindow::GetNewPageId() const
2012 sal_uInt16 i, nMax = 0, nCount = m_pTabCtrl->GetPageCount();
2013 for ( i = 0; i < nCount; ++i )
2015 if ( nMax < m_pTabCtrl->GetPageId(i) )
2016 nMax = m_pTabCtrl->GetPageId(i);
2018 return ( nMax + 1 );
2021 void DataNavigatorWindow::Resize()
2023 vcl::Window *pChild = GetWindow(GetWindowType::FirstChild);
2024 if (!pChild)
2025 return;
2026 VclContainer::setLayoutAllocation(*pChild, Point(0,0), GetSizePixel());
2029 Size DataNavigatorWindow::GetOptimalSize() const
2031 const vcl::Window *pChild = GetWindow(GetWindowType::FirstChild);
2032 if (!pChild)
2033 return Window::GetOptimalSize();
2034 return VclContainer::getLayoutRequisition(*pChild);
2037 void DataNavigatorWindow::SetDocModified()
2039 SfxObjectShell* pCurrentDoc = SfxObjectShell::Current();
2040 DBG_ASSERT( pCurrentDoc, "DataNavigatorWindow::SetDocModified(): no objectshell" );
2041 if ( !pCurrentDoc->IsModified() && pCurrentDoc->IsEnableSetModified() )
2042 pCurrentDoc->SetModified();
2045 void DataNavigatorWindow::NotifyChanges( bool _bLoadAll )
2047 if ( !m_bIsNotifyDisabled )
2049 if ( _bLoadAll )
2051 // reset all members
2052 RemoveBroadcaster();
2053 m_xDataContainer.clear();
2054 m_xFrameModel.clear();
2055 m_pModelsBox->Clear();
2056 m_nLastSelectedPos = LISTBOX_ENTRY_NOTFOUND;
2057 // for a reload
2058 LoadModels();
2060 else
2061 m_aUpdateTimer.Start();
2066 void DataNavigatorWindow::AddContainerBroadcaster( const css::uno::Reference< css::container::XContainer >& xContainer )
2068 Reference< XContainerListener > xListener(
2069 static_cast< XContainerListener* >( m_xDataListener.get() ), UNO_QUERY );
2070 xContainer->addContainerListener( xListener );
2071 m_aContainerList.push_back( xContainer );
2075 void DataNavigatorWindow::AddEventBroadcaster( const css::uno::Reference< css::xml::dom::events::XEventTarget >& xTarget )
2077 Reference< XEventListener > xListener(
2078 static_cast< XEventListener* >( m_xDataListener.get() ), UNO_QUERY );
2079 xTarget->addEventListener( EVENTTYPE_CHARDATA, xListener, true );
2080 xTarget->addEventListener( EVENTTYPE_CHARDATA, xListener, false );
2081 xTarget->addEventListener( EVENTTYPE_ATTR, xListener, true );
2082 xTarget->addEventListener( EVENTTYPE_ATTR, xListener, false );
2083 m_aEventTargetList.push_back( xTarget );
2087 void DataNavigatorWindow::RemoveBroadcaster()
2089 Reference< XContainerListener > xContainerListener(
2090 static_cast< XContainerListener* >( m_xDataListener.get() ), UNO_QUERY );
2091 sal_Int32 i, nCount = m_aContainerList.size();
2092 for ( i = 0; i < nCount; ++i )
2093 m_aContainerList[i]->removeContainerListener( xContainerListener );
2094 Reference< XEventListener > xEventListener(
2095 static_cast< XEventListener* >( m_xDataListener.get() ), UNO_QUERY );
2096 nCount = m_aEventTargetList.size();
2097 for ( i = 0; i < nCount; ++i )
2099 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_CHARDATA, xEventListener, true );
2100 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_CHARDATA, xEventListener, false );
2101 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_ATTR, xEventListener, true );
2102 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_ATTR, xEventListener, false );
2106 DataNavigator::DataNavigator( SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* _pParent ) :
2108 SfxDockingWindow( _pBindings, _pMgr, _pParent,
2109 WinBits(WB_STDMODELESS|WB_SIZEABLE|WB_ROLLABLE|WB_3DLOOK|WB_DOCKABLE) ),
2110 SfxControllerItem( SID_FM_DATANAVIGATOR_CONTROL, *_pBindings ),
2112 m_aDataWin( VclPtr<DataNavigatorWindow>::Create(this, _pBindings) )
2116 SetText( SvxResId( RID_STR_DATANAVIGATOR ) );
2118 Size aSize = m_aDataWin->GetOutputSizePixel();
2119 Size aLogSize = PixelToLogic(aSize, MapMode(MapUnit::MapAppFont));
2120 SfxDockingWindow::SetFloatingSize( aLogSize );
2122 m_aDataWin->Show();
2126 DataNavigator::~DataNavigator()
2128 disposeOnce();
2131 void DataNavigator::dispose()
2133 m_aDataWin.disposeAndClear();
2134 ::SfxControllerItem::dispose();
2135 SfxDockingWindow::dispose();
2138 void DataNavigator::StateChanged( sal_uInt16 , SfxItemState , const SfxPoolItem* )
2143 Size DataNavigator::CalcDockingSize( SfxChildAlignment eAlign )
2145 if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) )
2146 return Size();
2148 return SfxDockingWindow::CalcDockingSize( eAlign );
2152 SfxChildAlignment DataNavigator::CheckAlignment( SfxChildAlignment eActAlign, SfxChildAlignment eAlign )
2154 switch ( eAlign )
2156 case SfxChildAlignment::LEFT:
2157 case SfxChildAlignment::RIGHT:
2158 case SfxChildAlignment::NOALIGNMENT:
2159 return eAlign;
2160 default:
2161 break;
2163 return eActAlign;
2167 void DataNavigator::Resize()
2169 SfxDockingWindow::Resize();
2171 Size aLogOutputSize = PixelToLogic(GetOutputSizePixel(), MapMode(MapUnit::MapAppFont));
2172 Size aLogExplSize = aLogOutputSize;
2173 aLogExplSize.AdjustWidth( -2 );
2174 aLogExplSize.AdjustHeight( -2 );
2176 Point aExplPos = LogicToPixel(Point(1,1), MapMode(MapUnit::MapAppFont));
2177 Size aExplSize = LogicToPixel(aLogExplSize, MapMode(MapUnit::MapAppFont));
2179 m_aDataWin->SetPosSizePixel( aExplPos, aExplSize );
2183 // class NavigatorFrameManager
2186 SFX_IMPL_DOCKINGWINDOW( DataNavigatorManager, SID_FM_SHOW_DATANAVIGATOR )
2189 DataNavigatorManager::DataNavigatorManager(
2190 vcl::Window* _pParent, sal_uInt16 _nId, SfxBindings* _pBindings, SfxChildWinInfo* _pInfo ) :
2192 SfxChildWindow( _pParent, _nId )
2195 SetWindow( VclPtr<DataNavigator>::Create( _pBindings, this, _pParent ) );
2196 SetAlignment(SfxChildAlignment::RIGHT);
2197 GetWindow()->SetSizePixel( Size( 250, 400 ) );
2198 static_cast<SfxDockingWindow*>(GetWindow())->Initialize( _pInfo );
2201 AddDataItemDialog::AddDataItemDialog(weld::Window* pParent, ItemNode* _pNode,
2202 const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper)
2203 : GenericDialogController(pParent, "svx/ui/adddataitemdialog.ui", "AddDataItemDialog")
2204 , m_xUIHelper(_rUIHelper)
2205 , m_pItemNode(_pNode)
2206 , m_eItemType(DITNone)
2207 , m_sFL_Element(SvxResId(RID_STR_ELEMENT))
2208 , m_sFL_Attribute(SvxResId(RID_STR_ATTRIBUTE))
2209 , m_sFL_Binding(SvxResId(RID_STR_BINDING))
2210 , m_sFT_BindingExp(SvxResId(RID_STR_BINDING_EXPR))
2211 , m_xItemFrame(m_xBuilder->weld_frame("itemframe"))
2212 , m_xNameFT(m_xBuilder->weld_label("nameft"))
2213 , m_xNameED(m_xBuilder->weld_entry("name"))
2214 , m_xDefaultFT(m_xBuilder->weld_label("valueft"))
2215 , m_xDefaultED(m_xBuilder->weld_entry("value"))
2216 , m_xDefaultBtn(m_xBuilder->weld_button("browse"))
2217 , m_xSettingsFrame(m_xBuilder->weld_widget("settingsframe"))
2218 , m_xDataTypeFT(m_xBuilder->weld_label("datatypeft"))
2219 , m_xDataTypeLB(m_xBuilder->weld_combo_box("datatype"))
2220 , m_xRequiredCB(m_xBuilder->weld_check_button("required"))
2221 , m_xRequiredBtn(m_xBuilder->weld_button("requiredcond"))
2222 , m_xRelevantCB(m_xBuilder->weld_check_button("relevant"))
2223 , m_xRelevantBtn(m_xBuilder->weld_button("relevantcond"))
2224 , m_xConstraintCB(m_xBuilder->weld_check_button("constraint"))
2225 , m_xConstraintBtn(m_xBuilder->weld_button("constraintcond"))
2226 , m_xReadonlyCB(m_xBuilder->weld_check_button("readonly"))
2227 , m_xReadonlyBtn(m_xBuilder->weld_button("readonlycond"))
2228 , m_xCalculateCB(m_xBuilder->weld_check_button("calculate"))
2229 , m_xCalculateBtn(m_xBuilder->weld_button("calculatecond"))
2230 , m_xOKBtn(m_xBuilder->weld_button("ok"))
2232 InitDialog();
2233 InitFromNode();
2234 InitDataTypeBox();
2235 Check(nullptr);
2238 AddDataItemDialog::~AddDataItemDialog()
2240 if ( m_xTempBinding.is() )
2242 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2243 if ( xModel.is() )
2247 Reference < XSet > xBindings = xModel->getBindings();
2248 if ( xBindings.is() )
2249 xBindings->remove( makeAny( m_xTempBinding ) );
2251 catch (const Exception&)
2253 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::Dtor()" );
2257 if( m_xUIHelper.is() && m_xBinding.is() )
2259 // remove binding, if it does not convey 'useful' information
2260 m_xUIHelper->removeBindingIfUseless( m_xBinding );
2264 IMPL_LINK(AddDataItemDialog, CheckHdl, weld::ToggleButton&, rBox, void)
2266 Check(&rBox);
2269 void AddDataItemDialog::Check(const weld::ToggleButton* pBox)
2271 // Condition buttons are only enable if their check box is checked
2272 m_xReadonlyBtn->set_sensitive( m_xReadonlyCB->get_active() );
2273 m_xRequiredBtn->set_sensitive( m_xRequiredCB->get_active() );
2274 m_xRelevantBtn->set_sensitive( m_xRelevantCB->get_active() );
2275 m_xConstraintBtn->set_sensitive( m_xConstraintCB->get_active() );
2276 m_xCalculateBtn->set_sensitive( m_xCalculateCB->get_active() );
2278 if ( pBox && m_xTempBinding.is() )
2280 OUString sTemp, sPropName;
2281 if ( m_xRequiredCB.get() == pBox )
2282 sPropName = PN_REQUIRED_EXPR;
2283 else if ( m_xRelevantCB.get() == pBox )
2284 sPropName = PN_RELEVANT_EXPR;
2285 else if ( m_xConstraintCB.get() == pBox )
2286 sPropName = PN_CONSTRAINT_EXPR;
2287 else if ( m_xReadonlyCB.get() == pBox )
2288 sPropName = PN_READONLY_EXPR;
2289 else if ( m_xCalculateCB.get() == pBox )
2290 sPropName = PN_CALCULATE_EXPR;
2291 bool bIsChecked = pBox->get_active();
2292 m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp;
2293 if ( bIsChecked && sTemp.isEmpty() )
2294 sTemp = TRUE_VALUE;
2295 else if ( !bIsChecked && !sTemp.isEmpty() )
2296 sTemp.clear();
2297 m_xTempBinding->setPropertyValue( sPropName, makeAny( sTemp ) );
2301 IMPL_LINK(AddDataItemDialog, ConditionHdl, weld::Button&, rBtn, void)
2303 OUString sTemp, sPropName;
2304 if ( m_xDefaultBtn.get() == &rBtn )
2305 sPropName = PN_BINDING_EXPR;
2306 else if ( m_xRequiredBtn.get() == &rBtn )
2307 sPropName = PN_REQUIRED_EXPR;
2308 else if ( m_xRelevantBtn.get() == &rBtn )
2309 sPropName = PN_RELEVANT_EXPR;
2310 else if ( m_xConstraintBtn.get() == &rBtn )
2311 sPropName = PN_CONSTRAINT_EXPR;
2312 else if (m_xReadonlyBtn.get() == &rBtn)
2313 sPropName = PN_READONLY_EXPR;
2314 else if (m_xCalculateBtn.get() == &rBtn)
2315 sPropName = PN_CALCULATE_EXPR;
2316 AddConditionDialog aDlg(m_xDialog.get(), sPropName, m_xTempBinding);
2317 bool bIsDefBtn = ( m_xDefaultBtn.get() == &rBtn );
2318 OUString sCondition;
2319 if ( bIsDefBtn )
2320 sCondition = m_xDefaultED->get_text();
2321 else
2323 m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp;
2324 if ( sTemp.isEmpty() )
2325 sTemp = TRUE_VALUE;
2326 sCondition = sTemp;
2328 aDlg.SetCondition( sCondition );
2330 if (aDlg.run() == RET_OK)
2332 OUString sNewCondition = aDlg.GetCondition();
2333 if ( bIsDefBtn )
2334 m_xDefaultED->set_text(sNewCondition);
2335 else
2338 m_xTempBinding->setPropertyValue(
2339 sPropName, makeAny( sNewCondition ) );
2344 static void copyPropSet( const Reference< XPropertySet >& xFrom, Reference< XPropertySet > const & xTo )
2346 DBG_ASSERT( xFrom.is(), "copyPropSet(): no source" );
2347 DBG_ASSERT( xTo.is(), "copyPropSet(): no target" );
2351 // get property names & infos, and iterate over target properties
2352 const Sequence< Property > aProperties = xTo->getPropertySetInfo()->getProperties();
2353 Reference< XPropertySetInfo > xFromInfo = xFrom->getPropertySetInfo();
2354 for ( const Property& rProperty : aProperties )
2356 const OUString& rName = rProperty.Name;
2358 // if both set have the property, copy the value
2359 // (catch and ignore exceptions, if any)
2360 if ( xFromInfo->hasPropertyByName( rName ) )
2362 // don't set readonly properties
2363 Property aProperty = xFromInfo->getPropertyByName( rName );
2364 if ( ( aProperty.Attributes & PropertyAttribute::READONLY ) == 0 )
2365 xTo->setPropertyValue(rName, xFrom->getPropertyValue( rName ));
2367 // else: no property? then ignore.
2370 catch ( Exception const & )
2372 TOOLS_WARN_EXCEPTION( "svx.form", "copyPropSet()" );
2376 IMPL_LINK_NOARG(AddDataItemDialog, OKHdl, weld::Button&, void)
2378 bool bIsHandleBinding = ( DITBinding == m_eItemType );
2379 bool bIsHandleText = ( DITText == m_eItemType );
2380 OUString sNewName( m_xNameED->get_text() );
2382 if ( ( !bIsHandleBinding && !bIsHandleText && !m_xUIHelper->isValidXMLName( sNewName ) ) ||
2383 ( bIsHandleBinding && sNewName.isEmpty() ) )
2385 // Error and don't close the dialog
2386 std::unique_ptr<weld::MessageDialog> xErrBox(Application::CreateMessageDialog(m_xDialog.get(),
2387 VclMessageType::Warning, VclButtonsType::Ok,
2388 SvxResId(RID_STR_INVALID_XMLNAME)));
2389 xErrBox->set_primary_text(xErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sNewName));
2390 xErrBox->run();
2391 return;
2394 OUString sDataType( m_xDataTypeLB->get_active_text() );
2395 m_xTempBinding->setPropertyValue( PN_BINDING_TYPE, makeAny( sDataType ) );
2397 if ( bIsHandleBinding )
2399 // copy properties from temp binding to original binding
2400 copyPropSet( m_xTempBinding, m_pItemNode->m_xPropSet );
2403 OUString sValue = m_xNameED->get_text();
2404 m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_ID, makeAny( sValue ) );
2405 sValue = m_xDefaultED->get_text();
2406 m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_EXPR, makeAny( sValue ) );
2408 catch ( Exception const & )
2410 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataDialog::OKHdl()" );
2413 else
2415 // copy properties from temp binding to original binding
2416 copyPropSet( m_xTempBinding, m_xBinding );
2419 if ( bIsHandleText )
2420 m_xUIHelper->setNodeValue( m_pItemNode->m_xNode, m_xDefaultED->get_text() );
2421 else
2423 Reference< css::xml::dom::XNode > xNewNode =
2424 m_xUIHelper->renameNode( m_pItemNode->m_xNode, m_xNameED->get_text() );
2425 m_xUIHelper->setNodeValue( xNewNode, m_xDefaultED->get_text() );
2426 m_pItemNode->m_xNode = xNewNode;
2429 catch ( Exception const & )
2431 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataDialog::OKHdl()" );
2434 // then close the dialog
2435 m_xDialog->response(RET_OK);
2438 void AddDataItemDialog::InitDialog()
2440 // set handler
2441 Link<weld::ToggleButton&,void> aLink = LINK( this, AddDataItemDialog, CheckHdl );
2442 m_xRequiredCB->connect_toggled( aLink );
2443 m_xRelevantCB->connect_toggled( aLink );
2444 m_xConstraintCB->connect_toggled( aLink );
2445 m_xReadonlyCB->connect_toggled( aLink );
2446 m_xCalculateCB->connect_toggled( aLink );
2448 Link<weld::Button&,void> aLink2 = LINK( this, AddDataItemDialog, ConditionHdl );
2449 m_xDefaultBtn->connect_clicked( aLink2 );
2450 m_xRequiredBtn->connect_clicked( aLink2 );
2451 m_xRelevantBtn->connect_clicked( aLink2 );
2452 m_xConstraintBtn->connect_clicked( aLink2 );
2453 m_xReadonlyBtn->connect_clicked( aLink2 );
2454 m_xCalculateBtn->connect_clicked( aLink2 );
2456 m_xOKBtn->connect_clicked( LINK( this, AddDataItemDialog, OKHdl ) );
2459 void AddDataItemDialog::InitFromNode()
2461 if ( m_pItemNode )
2463 if ( m_pItemNode->m_xNode.is() )
2467 // detect type of the node
2468 css::xml::dom::NodeType eChildType = m_pItemNode->m_xNode->getNodeType();
2469 switch ( eChildType )
2471 case css::xml::dom::NodeType_ATTRIBUTE_NODE:
2472 m_eItemType = DITAttribute;
2473 break;
2474 case css::xml::dom::NodeType_ELEMENT_NODE:
2475 m_eItemType = DITElement;
2476 break;
2477 case css::xml::dom::NodeType_TEXT_NODE:
2478 m_eItemType = DITText;
2479 break;
2480 default:
2481 OSL_FAIL( "AddDataItemDialog::InitFronNode: cannot handle this node type!" );
2482 break;
2485 /** Get binding of the node and clone it
2486 Then use this temporary binding in the dialog.
2487 When the user click OK the temporary binding will be copied
2488 into the original binding.
2491 Reference< css::xml::dom::XNode > xNode = m_pItemNode->m_xNode;
2492 m_xBinding = m_xUIHelper->getBindingForNode( xNode, true );
2493 if ( m_xBinding.is() )
2495 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2496 if ( xModel.is() )
2498 m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_xBinding );
2499 Reference < XSet > xBindings = xModel->getBindings();
2500 if ( xBindings.is() )
2501 xBindings->insert( makeAny( m_xTempBinding ) );
2505 if ( m_eItemType != DITText )
2507 OUString sName( m_xUIHelper->getNodeName( m_pItemNode->m_xNode ) );
2508 m_xNameED->set_text( sName );
2510 m_xDefaultED->set_text( m_pItemNode->m_xNode->getNodeValue() );
2512 catch( Exception const & )
2514 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" );
2517 else if ( m_pItemNode->m_xPropSet.is() )
2519 m_eItemType = DITBinding;
2520 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2521 if ( xModel.is() )
2525 m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_pItemNode->m_xPropSet );
2526 Reference < XSet > xBindings = xModel->getBindings();
2527 if ( xBindings.is() )
2528 xBindings->insert( makeAny( m_xTempBinding ) );
2530 catch ( Exception const & )
2532 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" );
2535 OUString sTemp;
2538 Reference< XPropertySetInfo > xInfo = m_pItemNode->m_xPropSet->getPropertySetInfo();
2539 if ( xInfo->hasPropertyByName( PN_BINDING_ID ) )
2541 m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
2542 m_xNameED->set_text( sTemp );
2543 m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
2544 m_xDefaultED->set_text( sTemp );
2546 else if ( xInfo->hasPropertyByName( PN_SUBMISSION_BIND ) )
2548 m_pItemNode->m_xPropSet->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
2549 m_xNameED->set_text( sTemp );
2552 catch( Exception const & )
2554 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" );
2557 m_xDefaultBtn->show();
2560 if ( m_xTempBinding.is() )
2562 OUString sTemp;
2565 if ( ( m_xTempBinding->getPropertyValue( PN_REQUIRED_EXPR ) >>= sTemp )
2566 && !sTemp.isEmpty() )
2567 m_xRequiredCB->set_active(true);
2568 if ( ( m_xTempBinding->getPropertyValue( PN_RELEVANT_EXPR ) >>= sTemp )
2569 && !sTemp.isEmpty() )
2570 m_xRelevantCB->set_active(true);
2571 if ( ( m_xTempBinding->getPropertyValue( PN_CONSTRAINT_EXPR ) >>= sTemp )
2572 && !sTemp.isEmpty() )
2573 m_xConstraintCB->set_active(true);
2574 if ( ( m_xTempBinding->getPropertyValue( PN_READONLY_EXPR ) >>= sTemp )
2575 && !sTemp.isEmpty() )
2576 m_xReadonlyCB->set_active(true);
2577 if ( ( m_xTempBinding->getPropertyValue( PN_CALCULATE_EXPR ) >>= sTemp )
2578 && !sTemp.isEmpty() )
2579 m_xCalculateCB->set_active(true);
2581 catch (const Exception&)
2583 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitFromNode()" );
2588 if ( DITText == m_eItemType )
2590 m_xSettingsFrame->hide();
2591 m_xNameFT->set_sensitive(false);
2592 m_xNameED->set_sensitive(false);
2596 void AddDataItemDialog::InitDataTypeBox()
2598 if ( m_eItemType != DITText )
2600 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2601 if ( xModel.is() )
2605 Reference< css::xforms::XDataTypeRepository > xDataTypes =
2606 xModel->getDataTypeRepository();
2607 if ( xDataTypes.is() )
2609 const Sequence< OUString > aNameList = xDataTypes->getElementNames();
2610 for ( const OUString& rName : aNameList )
2611 m_xDataTypeLB->append_text(rName);
2614 if ( m_xTempBinding.is() )
2616 OUString sTemp;
2617 if ( m_xTempBinding->getPropertyValue( PN_BINDING_TYPE ) >>= sTemp )
2619 int nPos = m_xDataTypeLB->find_text(sTemp);
2620 if (nPos == -1)
2622 m_xDataTypeLB->append_text(sTemp);
2623 nPos = m_xDataTypeLB->get_count() - 1;
2625 m_xDataTypeLB->set_active(nPos);
2629 catch ( Exception const & )
2631 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::InitDataTypeBox()" );
2637 void AddDataItemDialog::InitText( DataItemType _eType )
2639 OUString sText;
2641 switch ( _eType )
2643 case DITAttribute :
2645 sText = m_sFL_Attribute;
2646 break;
2649 case DITBinding :
2651 sText = m_sFL_Binding;
2652 m_xDefaultFT->set_label(m_sFT_BindingExp);
2653 break;
2656 default:
2658 sText = m_sFL_Element;
2662 m_xItemFrame->set_label(sText);
2665 AddConditionDialog::AddConditionDialog(weld::Window* pParent,
2666 const OUString& _rPropertyName,
2667 const Reference< XPropertySet >& _rPropSet)
2668 : GenericDialogController(pParent, "svx/ui/addconditiondialog.ui", "AddConditionDialog")
2669 , m_sPropertyName(_rPropertyName)
2670 , m_xBinding(_rPropSet)
2671 , m_xConditionED(m_xBuilder->weld_text_view("condition"))
2672 , m_xResultWin(m_xBuilder->weld_text_view("result"))
2673 , m_xEditNamespacesBtn(m_xBuilder->weld_button("edit"))
2674 , m_xOKBtn(m_xBuilder->weld_button("ok"))
2676 DBG_ASSERT( m_xBinding.is(), "AddConditionDialog::Ctor(): no Binding" );
2678 m_xConditionED->set_size_request(m_xConditionED->get_approximate_digit_width() * 52,
2679 m_xConditionED->get_height_rows(4));
2680 m_xResultWin->set_size_request(m_xResultWin->get_approximate_digit_width() * 52,
2681 m_xResultWin->get_height_rows(4));
2683 m_xConditionED->connect_changed( LINK( this, AddConditionDialog, ModifyHdl ) );
2684 m_xEditNamespacesBtn->connect_clicked( LINK( this, AddConditionDialog, EditHdl ) );
2685 m_xOKBtn->connect_clicked( LINK( this, AddConditionDialog, OKHdl ) );
2686 m_aResultIdle.SetPriority( TaskPriority::LOWEST );
2687 m_aResultIdle.SetInvokeHandler( LINK( this, AddConditionDialog, ResultHdl ) );
2689 if ( !m_sPropertyName.isEmpty() )
2693 OUString sTemp;
2694 if ( ( m_xBinding->getPropertyValue( m_sPropertyName ) >>= sTemp )
2695 && !sTemp.isEmpty() )
2697 m_xConditionED->set_text( sTemp );
2699 else
2701 //! m_xBinding->setPropertyValue( m_sPropertyName, makeAny( TRUE_VALUE ) );
2702 m_xConditionED->set_text( TRUE_VALUE );
2705 Reference< css::xforms::XModel > xModel;
2706 if ( ( m_xBinding->getPropertyValue( PN_BINDING_MODEL ) >>= xModel ) && xModel.is() )
2707 m_xUIHelper.set( xModel, UNO_QUERY );
2709 catch (const Exception&)
2711 TOOLS_WARN_EXCEPTION( "svx.form", "AddConditionDialog::Ctor()" );
2715 DBG_ASSERT( m_xUIHelper.is(), "AddConditionDialog::Ctor(): no UIHelper" );
2716 ResultHdl( &m_aResultIdle );
2719 AddConditionDialog::~AddConditionDialog()
2723 IMPL_LINK_NOARG(AddConditionDialog, EditHdl, weld::Button&, void)
2725 Reference< XNameContainer > xNameContnr;
2728 m_xBinding->getPropertyValue( PN_BINDING_NAMESPACES ) >>= xNameContnr;
2730 catch ( Exception const & )
2732 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::EditHdl()" );
2734 NamespaceItemDialog aDlg(this, xNameContnr);
2735 aDlg.run();
2738 m_xBinding->setPropertyValue( PN_BINDING_NAMESPACES, makeAny( xNameContnr ) );
2740 catch ( Exception const & )
2742 TOOLS_WARN_EXCEPTION( "svx.form", "AddDataItemDialog::EditHdl()" );
2746 IMPL_LINK_NOARG(AddConditionDialog, OKHdl, weld::Button&, void)
2748 m_xDialog->response(RET_OK);
2751 IMPL_LINK_NOARG(AddConditionDialog, ModifyHdl, weld::TextView&, void)
2753 m_aResultIdle.Start();
2756 IMPL_LINK_NOARG(AddConditionDialog, ResultHdl, Timer *, void)
2758 OUString sCondition = comphelper::string::strip(m_xConditionED->get_text(), ' ');
2759 OUString sResult;
2760 if ( !sCondition.isEmpty() )
2764 sResult = m_xUIHelper->getResultForExpression( m_xBinding, ( m_sPropertyName == PN_BINDING_EXPR ), sCondition );
2766 catch ( Exception const & )
2768 TOOLS_WARN_EXCEPTION( "svx.form", "AddConditionDialog::ResultHdl()" );
2771 m_xResultWin->set_text(sResult);
2774 NamespaceItemDialog::NamespaceItemDialog(AddConditionDialog* pCondDlg, Reference<XNameContainer>& rContainer)
2775 : GenericDialogController(pCondDlg->getDialog(), "svx/ui/namespacedialog.ui", "NamespaceDialog")
2776 , m_pConditionDlg(pCondDlg)
2777 , m_rNamespaces(rContainer)
2778 , m_xNamespacesList(m_xBuilder->weld_tree_view("namespaces"))
2779 , m_xAddNamespaceBtn(m_xBuilder->weld_button("add"))
2780 , m_xEditNamespaceBtn(m_xBuilder->weld_button("edit"))
2781 , m_xDeleteNamespaceBtn(m_xBuilder->weld_button("delete"))
2782 , m_xOKBtn(m_xBuilder->weld_button("ok"))
2784 m_xNamespacesList->set_size_request(m_xNamespacesList->get_approximate_digit_width() * 80,
2785 m_xNamespacesList->get_height_rows(8));
2787 std::vector<int> aWidths;
2788 aWidths.push_back(m_xNamespacesList->get_approximate_digit_width() * 20);
2789 m_xNamespacesList->set_column_fixed_widths(aWidths);
2791 m_xNamespacesList->connect_changed( LINK( this, NamespaceItemDialog, SelectHdl ) );
2792 Link<weld::Button&,void> aLink = LINK( this, NamespaceItemDialog, ClickHdl );
2793 m_xAddNamespaceBtn->connect_clicked( aLink );
2794 m_xEditNamespaceBtn->connect_clicked( aLink );
2795 m_xDeleteNamespaceBtn->connect_clicked( aLink );
2796 m_xOKBtn->connect_clicked( LINK( this, NamespaceItemDialog, OKHdl ) );
2798 LoadNamespaces();
2799 SelectHdl(*m_xNamespacesList);
2802 NamespaceItemDialog::~NamespaceItemDialog()
2806 IMPL_LINK_NOARG( NamespaceItemDialog, SelectHdl, weld::TreeView&, void)
2808 bool bEnable = m_xNamespacesList->get_selected_index() != -1;
2809 m_xEditNamespaceBtn->set_sensitive( bEnable );
2810 m_xDeleteNamespaceBtn->set_sensitive( bEnable );
2813 IMPL_LINK( NamespaceItemDialog, ClickHdl, weld::Button&, rButton, void )
2815 if (m_xAddNamespaceBtn.get() == &rButton)
2817 ManageNamespaceDialog aDlg(m_xDialog.get(), m_pConditionDlg, false);
2818 if (aDlg.run() == RET_OK)
2820 m_xNamespacesList->append_text(aDlg.GetPrefix());
2821 int nRow = m_xNamespacesList->n_children();
2822 m_xNamespacesList->set_text(nRow - 1, aDlg.GetURL(), 1);
2825 else if (m_xEditNamespaceBtn.get() == &rButton)
2827 ManageNamespaceDialog aDlg(m_xDialog.get(), m_pConditionDlg, true);
2828 int nEntry = m_xNamespacesList->get_selected_index();
2829 DBG_ASSERT( nEntry != -1, "NamespaceItemDialog::ClickHdl(): no entry" );
2830 OUString sPrefix(m_xNamespacesList->get_text(nEntry, 0));
2831 aDlg.SetNamespace(sPrefix, m_xNamespacesList->get_text(nEntry, 1));
2832 if (aDlg.run() == RET_OK)
2834 // if a prefix was changed, mark the old prefix as 'removed'
2835 if( sPrefix != aDlg.GetPrefix() )
2836 m_aRemovedList.push_back( sPrefix );
2838 m_xNamespacesList->set_text(nEntry, aDlg.GetPrefix(), 0);
2839 m_xNamespacesList->set_text(nEntry, aDlg.GetURL(), 1);
2842 else if (m_xDeleteNamespaceBtn.get() == &rButton)
2844 int nEntry = m_xNamespacesList->get_selected_index();
2845 DBG_ASSERT( nEntry != -1, "NamespaceItemDialog::ClickHdl(): no entry" );
2846 OUString sPrefix(m_xNamespacesList->get_text(nEntry, 0));
2847 m_aRemovedList.push_back( sPrefix );
2848 m_xNamespacesList->remove(nEntry);
2850 else
2852 SAL_WARN( "svx.form", "NamespaceItemDialog::ClickHdl(): invalid button" );
2855 SelectHdl(*m_xNamespacesList);
2858 IMPL_LINK_NOARG(NamespaceItemDialog, OKHdl, weld::Button&, void)
2862 // update namespace container
2863 sal_Int32 i, nRemovedCount = m_aRemovedList.size();
2864 for( i = 0; i < nRemovedCount; ++i )
2865 m_rNamespaces->removeByName( m_aRemovedList[i] );
2867 sal_Int32 nEntryCount = m_xNamespacesList->n_children();
2868 for( i = 0; i < nEntryCount; ++i )
2870 OUString sPrefix(m_xNamespacesList->get_text(i, 0));
2871 OUString sURL(m_xNamespacesList->get_text(i, 1));
2873 if ( m_rNamespaces->hasByName( sPrefix ) )
2874 m_rNamespaces->replaceByName( sPrefix, makeAny( sURL ) );
2875 else
2876 m_rNamespaces->insertByName( sPrefix, makeAny( sURL ) );
2879 catch ( Exception const & )
2881 TOOLS_WARN_EXCEPTION( "svx.form", "NamespaceItemDialog::OKHdl()" );
2883 // and close the dialog
2884 m_xDialog->response(RET_OK);
2887 void NamespaceItemDialog::LoadNamespaces()
2891 int nRow = 0;
2892 const Sequence< OUString > aAllNames = m_rNamespaces->getElementNames();
2893 for ( const OUString& sPrefix : aAllNames )
2895 if ( m_rNamespaces->hasByName( sPrefix ) )
2897 OUString sURL;
2898 Any aAny = m_rNamespaces->getByName( sPrefix );
2899 if (aAny >>= sURL)
2901 m_xNamespacesList->append_text(sPrefix);
2902 m_xNamespacesList->set_text(nRow, sURL, 1);
2903 ++nRow;
2908 catch ( Exception const & )
2910 TOOLS_WARN_EXCEPTION( "svx.form", "NamespaceItemDialog::LoadNamespaces()" );
2914 ManageNamespaceDialog::ManageNamespaceDialog(weld::Window* pParent, AddConditionDialog* pCondDlg, bool bIsEdit)
2915 : GenericDialogController(pParent, "svx/ui/addnamespacedialog.ui", "AddNamespaceDialog")
2916 , m_pConditionDlg(pCondDlg)
2917 , m_xPrefixED(m_xBuilder->weld_entry("prefix"))
2918 , m_xUrlED(m_xBuilder->weld_entry("url"))
2919 , m_xOKBtn(m_xBuilder->weld_button("ok"))
2920 , m_xAltTitle(m_xBuilder->weld_label("alttitle"))
2922 if (bIsEdit)
2923 m_xDialog->set_title(m_xAltTitle->get_label());
2925 m_xOKBtn->connect_clicked(LINK(this, ManageNamespaceDialog, OKHdl));
2928 ManageNamespaceDialog::~ManageNamespaceDialog()
2932 IMPL_LINK_NOARG(ManageNamespaceDialog, OKHdl, weld::Button&, void)
2934 OUString sPrefix = m_xPrefixED->get_text();
2938 if (!m_pConditionDlg->GetUIHelper()->isValidPrefixName(sPrefix))
2940 std::unique_ptr<weld::MessageDialog> xErrBox(Application::CreateMessageDialog(m_xDialog.get(),
2941 VclMessageType::Warning, VclButtonsType::Ok,
2942 SvxResId(RID_STR_INVALID_XMLPREFIX)));
2943 xErrBox->set_primary_text(xErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sPrefix));
2944 xErrBox->run();
2945 return;
2948 catch ( Exception const & )
2950 TOOLS_WARN_EXCEPTION( "svx.form", "ManageNamespacesDialog::OKHdl()" );
2953 // no error so close the dialog
2954 m_xDialog->response(RET_OK);
2957 AddSubmissionDialog::AddSubmissionDialog(
2958 weld::Window* pParent, ItemNode* _pNode,
2959 const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper)
2960 : GenericDialogController(pParent, "svx/ui/addsubmissiondialog.ui", "AddSubmissionDialog")
2961 , m_pItemNode(_pNode)
2962 , m_xUIHelper(_rUIHelper)
2963 , m_xNameED(m_xBuilder->weld_entry("name"))
2964 , m_xActionED(m_xBuilder->weld_entry("action"))
2965 , m_xMethodLB(m_xBuilder->weld_combo_box("method"))
2966 , m_xRefED(m_xBuilder->weld_entry("expression"))
2967 , m_xRefBtn(m_xBuilder->weld_button("browse"))
2968 , m_xBindLB(m_xBuilder->weld_combo_box("binding"))
2969 , m_xReplaceLB(m_xBuilder->weld_combo_box("replace"))
2970 , m_xOKBtn(m_xBuilder->weld_button("ok"))
2972 FillAllBoxes();
2974 m_xRefBtn->connect_clicked( LINK( this, AddSubmissionDialog, RefHdl ) );
2975 m_xOKBtn->connect_clicked( LINK( this, AddSubmissionDialog, OKHdl ) );
2978 AddSubmissionDialog::~AddSubmissionDialog()
2980 // #i38991# if we have added a binding, we need to remove it as well.
2981 if( m_xCreatedBinding.is() && m_xUIHelper.is() )
2982 m_xUIHelper->removeBindingIfUseless( m_xCreatedBinding );
2985 IMPL_LINK_NOARG(AddSubmissionDialog, RefHdl, weld::Button&, void)
2987 AddConditionDialog aDlg(m_xDialog.get(), PN_BINDING_EXPR, m_xTempBinding );
2988 aDlg.SetCondition( m_xRefED->get_text() );
2989 if ( aDlg.run() == RET_OK )
2990 m_xRefED->set_text(aDlg.GetCondition());
2993 IMPL_LINK_NOARG(AddSubmissionDialog, OKHdl, weld::Button&, void)
2995 OUString sName(m_xNameED->get_text());
2996 if(sName.isEmpty())
2998 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(m_xDialog.get(),
2999 VclMessageType::Warning, VclButtonsType::Ok,
3000 SvxResId(RID_STR_EMPTY_SUBMISSIONNAME)));
3001 xErrorBox->set_primary_text(Application::GetDisplayName());
3002 xErrorBox->run();
3003 return;
3006 if ( !m_xSubmission.is() )
3008 DBG_ASSERT( !m_xNewSubmission.is(),
3009 "AddSubmissionDialog::OKHdl(): new submission already exists" );
3011 // add a new submission
3012 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
3013 if ( xModel.is() )
3017 m_xNewSubmission = xModel->createSubmission();
3018 m_xSubmission = m_xNewSubmission;
3020 catch ( Exception const & )
3022 TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::OKHdl()" );
3027 if ( m_xSubmission.is() )
3029 OUString sTemp = m_xNameED->get_text();
3032 m_xSubmission->setPropertyValue( PN_SUBMISSION_ID, makeAny( sTemp ) );
3033 sTemp = m_xActionED->get_text();
3034 m_xSubmission->setPropertyValue( PN_SUBMISSION_ACTION, makeAny( sTemp ) );
3035 sTemp = m_aMethodString.toAPI( m_xMethodLB->get_active_text() );
3036 m_xSubmission->setPropertyValue( PN_SUBMISSION_METHOD, makeAny( sTemp ) );
3037 sTemp = m_xRefED->get_text();
3038 m_xSubmission->setPropertyValue( PN_SUBMISSION_REF, makeAny( sTemp ) );
3039 OUString sEntry = m_xBindLB->get_active_text();
3040 sal_Int32 nColonIdx = sEntry.indexOf(':');
3041 if (nColonIdx != -1)
3042 sEntry = sEntry.copy(0, nColonIdx);
3043 sTemp = sEntry;
3044 m_xSubmission->setPropertyValue( PN_SUBMISSION_BIND, makeAny( sTemp ) );
3045 sTemp = m_aReplaceString.toAPI( m_xReplaceLB->get_active_text() );
3046 m_xSubmission->setPropertyValue( PN_SUBMISSION_REPLACE, makeAny( sTemp ) );
3048 catch ( Exception const & )
3050 TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::OKHdl()" );
3054 m_xDialog->response(RET_OK);
3057 void AddSubmissionDialog::FillAllBoxes()
3059 // method box
3060 m_xMethodLB->append_text(SvxResId(RID_STR_METHOD_POST));
3061 m_xMethodLB->append_text(SvxResId(RID_STR_METHOD_PUT));
3062 m_xMethodLB->append_text(SvxResId(RID_STR_METHOD_GET));
3063 m_xMethodLB->set_active(0);
3065 // binding box
3066 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
3067 if ( xModel.is() )
3071 Reference< XEnumerationAccess > xNumAccess = xModel->getBindings();
3072 if ( xNumAccess.is() )
3074 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
3075 if ( xNum.is() && xNum->hasMoreElements() )
3077 while ( xNum->hasMoreElements() )
3079 Reference< XPropertySet > xPropSet;
3080 Any aAny = xNum->nextElement();
3081 if ( aAny >>= xPropSet )
3083 OUString sEntry;
3084 OUString sTemp;
3085 xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
3086 sEntry += sTemp + ": ";
3087 xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
3088 sEntry += sTemp;
3089 m_xBindLB->append_text(sEntry);
3091 if ( !m_xTempBinding.is() )
3092 m_xTempBinding = xPropSet;
3098 catch ( Exception const & )
3100 TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::FillAllBoxes()" );
3104 // #i36342# we need a temporary binding; create one if no existing binding
3105 // is found
3106 if( !m_xTempBinding.is() )
3108 m_xCreatedBinding = m_xUIHelper->getBindingForNode(
3109 Reference<css::xml::dom::XNode>(
3110 xModel->getDefaultInstance()->getDocumentElement(),
3111 UNO_QUERY_THROW ),
3112 true );
3113 m_xTempBinding = m_xCreatedBinding;
3116 // replace box
3117 m_xReplaceLB->append_text(SvxResId(RID_STR_REPLACE_NONE));
3118 m_xReplaceLB->append_text(SvxResId(RID_STR_REPLACE_INST));
3119 m_xReplaceLB->append_text(SvxResId(RID_STR_REPLACE_DOC));
3122 // init the controls with the values of the submission
3123 if ( m_pItemNode && m_pItemNode->m_xPropSet.is() )
3125 m_xSubmission = m_pItemNode->m_xPropSet;
3126 OUString sTemp;
3129 m_xSubmission->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
3130 m_xNameED->set_text( sTemp );
3131 m_xSubmission->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp;
3132 m_xActionED->set_text( sTemp );
3133 m_xSubmission->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp;
3134 m_xRefED->set_text(sTemp);
3136 m_xSubmission->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp;
3137 sTemp = m_aMethodString.toUI( sTemp );
3138 sal_Int32 nPos = m_xMethodLB->find_text( sTemp );
3139 if (nPos == -1)
3141 m_xMethodLB->append_text( sTemp );
3142 nPos = m_xMethodLB->get_count() - 1;
3144 m_xMethodLB->set_active( nPos );
3146 m_xSubmission->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp;
3147 nPos = m_xBindLB->find_text(sTemp);
3148 if (nPos == -1)
3150 m_xBindLB->append_text(sTemp);
3151 nPos = m_xBindLB->get_count() - 1;
3153 m_xBindLB->set_active(nPos);
3155 m_xSubmission->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp;
3156 sTemp = m_aReplaceString.toUI( sTemp );
3157 if ( sTemp.isEmpty() )
3158 sTemp = m_xReplaceLB->get_text(0); // first entry == "none"
3159 nPos = m_xReplaceLB->find_text(sTemp);
3160 if (nPos == -1)
3162 m_xReplaceLB->append_text(sTemp);
3163 nPos = m_xReplaceLB->get_count() - 1;
3165 m_xReplaceLB->set_active(nPos);
3167 catch ( Exception const & )
3169 TOOLS_WARN_EXCEPTION( "svx.form", "AddSubmissionDialog::FillAllBoxes()" );
3173 m_xRefBtn->set_sensitive(m_xTempBinding.is());
3176 AddModelDialog::AddModelDialog(weld::Window* pParent, bool bIsEdit)
3177 : GenericDialogController(pParent, "svx/ui/addmodeldialog.ui", "AddModelDialog")
3178 , m_xNameED(m_xBuilder->weld_entry("name"))
3179 , m_xModifyCB(m_xBuilder->weld_check_button("modify"))
3180 , m_xAltTitle(m_xBuilder->weld_label("alttitle"))
3182 if (bIsEdit)
3183 m_xDialog->set_title(m_xAltTitle->get_label());
3186 AddModelDialog::~AddModelDialog()
3190 AddInstanceDialog::AddInstanceDialog(weld::Window* pParent, bool _bEdit)
3191 : GenericDialogController(pParent, "svx/ui/addinstancedialog.ui", "AddInstanceDialog")
3192 , m_xNameED(m_xBuilder->weld_entry("name"))
3193 , m_xURLFT(m_xBuilder->weld_label("urlft"))
3194 , m_xURLED(new URLBox(m_xBuilder->weld_combo_box("url")))
3195 , m_xFilePickerBtn(m_xBuilder->weld_button("browse"))
3196 , m_xLinkInstanceCB(m_xBuilder->weld_check_button("link"))
3197 , m_xAltTitle(m_xBuilder->weld_label("alttitle"))
3199 if (_bEdit)
3200 m_xDialog->set_title(m_xAltTitle->get_label());
3202 m_xURLED->DisableHistory();
3203 m_xFilePickerBtn->connect_clicked(LINK(this, AddInstanceDialog, FilePickerHdl));
3205 // load the filter name from fps resource
3206 m_sAllFilterName = Translate::get(STR_FILTERNAME_ALL, Translate::Create("fps"));
3209 AddInstanceDialog::~AddInstanceDialog()
3213 IMPL_LINK_NOARG(AddInstanceDialog, FilePickerHdl, weld::Button&, void)
3215 ::sfx2::FileDialogHelper aDlg(
3216 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
3217 FileDialogFlags::NONE, m_xDialog.get());
3218 INetURLObject aFile( SvtPathOptions().GetWorkPath() );
3220 aDlg.AddFilter( m_sAllFilterName, FILEDIALOG_FILTER_ALL );
3221 OUString sFilterName( "XML" );
3222 aDlg.AddFilter( sFilterName, "*.xml" );
3223 aDlg.SetCurrentFilter( sFilterName );
3224 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
3226 if (aDlg.Execute() == ERRCODE_NONE)
3227 m_xURLED->set_entry_text(aDlg.GetPath());
3230 LinkedInstanceWarningBox::LinkedInstanceWarningBox(weld::Widget* pParent)
3231 : MessageDialogController(pParent, "svx/ui/formlinkwarndialog.ui",
3232 "FormLinkWarnDialog")
3238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */