bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / form / datanavi.cxx
bloba37439eda1caf31e648a92de7da4b2782bc11718
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 .
21 #include <sal/macros.h>
22 #include "datanavi.hxx"
23 #include "fmservs.hxx"
25 #include "datanavi.hrc"
26 #include "fmhelp.hrc"
27 #include <svx/svxids.hrc>
28 #include <tools/rcid.h>
29 #include <tools/diagnose_ex.h>
30 #include <svx/xmlexchg.hxx>
31 #include <svx/fmshell.hxx>
32 #include <svtools/miscopt.hxx>
33 #include <unotools/pathoptions.hxx>
34 #include <unotools/viewoptions.hxx>
35 #include <svtools/svtools.hrc>
36 #include "svtools/treelistentry.hxx"
37 #include <sfx2/app.hxx>
38 #include <sfx2/filedlghelper.hxx>
39 #include <sfx2/objitem.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/bindings.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <vcl/layout.hxx>
45 #include <vcl/builderfactory.hxx>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 #include <com/sun/star/container/XSet.hpp>
48 #include <com/sun/star/datatransfer/XTransferable.hpp>
49 #include <com/sun/star/frame/XController.hpp>
50 #include <com/sun/star/frame/XFramesSupplier.hpp>
51 #include <com/sun/star/frame/XModel.hpp>
52 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
53 #include <com/sun/star/xforms/XFormsSupplier.hpp>
54 #include <com/sun/star/xml/dom/XDocument.hpp>
55 #include <com/sun/star/xml/dom/DOMException.hpp>
56 #include <com/sun/star/form/binding/XValueBinding.hpp>
57 #include <comphelper/processfactory.hxx>
58 #include <comphelper/string.hxx>
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::datatransfer;
63 using namespace ::com::sun::star::frame;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::xml::dom::events;
66 using namespace ::svx;
68 #define CFGNAME_DATANAVIGATOR "DataNavigator"
69 #define CFGNAME_SHOWDETAILS "ShowDetails"
70 #define MSG_VARIABLE "%1"
71 #define MODELNAME "$MODELNAME"
72 #define INSTANCENAME "$INSTANCENAME"
73 #define ELEMENTNAME "$ELEMENTNAME"
74 #define ATTRIBUTENAME "$ATTRIBUTENAME"
75 #define SUBMISSIONNAME "$SUBMISSIONNAME"
76 #define BINDINGNAME "$BINDINGNAME"
79 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 ItemNode( const Reference< css::xml::dom::XNode >& _rxNode ) :
123 m_xNode( _rxNode ) {}
124 ItemNode( const Reference< XPropertySet >& _rxSet ) :
125 m_xPropSet( _rxSet ) {}
128 DataTreeListBox::DataTreeListBox(vcl::Window* pParent, WinBits nBits)
129 : SvTreeListBox(pParent, nBits)
130 , m_pXFormsPage(NULL)
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_pXFormsPage.clear();
153 SvTreeListBox::dispose();
156 sal_Int8 DataTreeListBox::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
158 return DND_ACTION_NONE;
160 sal_Int8 DataTreeListBox::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
162 return DND_ACTION_NONE;
164 void DataTreeListBox::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
166 SvTreeListEntry* pSelected = FirstSelected();
167 if ( !pSelected )
168 // no drag without an entry
169 return;
171 if ( m_eGroup == DGTBinding )
172 // for the moment, bindings cannot be dragged.
173 // #i59395# / 2005-12-15 / frank.schoenheit@sun.com
174 return;
176 // GetServiceNameForNode() requires a datatype repository which
177 // will be automatically build if requested???
178 Reference< css::xforms::XModel > xModel( m_pXFormsPage->GetXFormsHelper(), UNO_QUERY );
179 Reference< css::xforms::XDataTypeRepository > xDataTypes =
180 xModel->getDataTypeRepository();
181 if(!xDataTypes.is())
182 return;
184 using namespace ::com::sun::star::uno;
186 ItemNode *pItemNode = static_cast<ItemNode*>(pSelected->GetUserData());
188 if ( !pItemNode )
190 // the only known (and allowed?) case where this happens are sub-entries of a submission
191 // entry
192 DBG_ASSERT( DGTSubmission == m_eGroup, "DataTreeListBox::StartDrag: how this?" );
193 pSelected = GetParent( pSelected );
194 DBG_ASSERT( pSelected && !GetParent( pSelected ), "DataTreeListBox::StartDrag: what kind of entry *is* this?" );
195 // on the submission page, we have only top-level entries (the submission themself)
196 // plus direct children of those (facets of a submission)
197 pItemNode = pSelected ? static_cast< ItemNode* >( pSelected->GetUserData() ) : NULL;
198 if ( !pItemNode )
199 return;
202 OXFormsDescriptor desc;
203 desc.szName = GetEntryText(pSelected);
204 if(pItemNode->m_xNode.is()) {
205 // a valid node interface tells us that we need to create a control from a binding
206 desc.szServiceName = m_pXFormsPage->GetServiceNameForNode(pItemNode->m_xNode);
207 desc.xPropSet = m_pXFormsPage->GetBindingForNode(pItemNode->m_xNode);
208 DBG_ASSERT( desc.xPropSet.is(), "DataTreeListBox::StartDrag(): invalid node binding" );
210 else {
211 desc.szServiceName = FM_COMPONENT_COMMANDBUTTON;
212 desc.xPropSet = pItemNode->m_xPropSet;
214 OXFormsTransferable *pTransferable = new OXFormsTransferable(desc);
215 Reference< XTransferable > xEnsureDelete = pTransferable;
216 EndSelection();
217 pTransferable->StartDrag( this, DND_ACTION_COPY );
220 PopupMenu* DataTreeListBox::CreateContextMenu()
222 PopupMenu* pMenu = new PopupMenu( SVX_RES( RID_MENU_DATANAVIGATOR ) );
223 if ( DGTInstance == m_eGroup )
224 pMenu->RemoveItem( pMenu->GetItemPos( m_nAddId ) );
225 else
227 pMenu->RemoveItem( pMenu->GetItemPos( m_nAddElementId ) );
228 pMenu->RemoveItem( pMenu->GetItemPos( m_nAddAttributeId ) );
230 if ( DGTSubmission == m_eGroup )
232 pMenu->SetItemText( m_nAddId, SVX_RESSTR( RID_STR_DATANAV_ADD_SUBMISSION ) );
233 pMenu->SetItemText( m_nEditId, SVX_RESSTR( RID_STR_DATANAV_EDIT_SUBMISSION ) );
234 pMenu->SetItemText( m_nRemoveId, SVX_RESSTR( RID_STR_DATANAV_REMOVE_SUBMISSION ) );
236 else
238 pMenu->SetItemText( m_nAddId, SVX_RESSTR( RID_STR_DATANAV_ADD_BINDING ) );
239 pMenu->SetItemText( m_nEditId, SVX_RESSTR( RID_STR_DATANAV_EDIT_BINDING ) );
240 pMenu->SetItemText( m_nRemoveId, SVX_RESSTR( RID_STR_DATANAV_REMOVE_BINDING ) );
243 m_pXFormsPage->EnableMenuItems( pMenu );
244 return pMenu;
247 void DataTreeListBox::ExcecuteContextMenuAction( sal_uInt16 _nSelectedPopupEntry )
249 m_pXFormsPage->DoMenuAction( _nSelectedPopupEntry );
252 void DataTreeListBox::RemoveEntry( SvTreeListEntry* _pEntry )
254 if ( _pEntry )
256 delete static_cast< ItemNode* >( _pEntry->GetUserData() );
257 SvTreeListBox::GetModel()->Remove( _pEntry );
261 void DataTreeListBox::SetGroup(DataGroupType _eGroup)
263 m_eGroup = _eGroup;
266 void DataTreeListBox::SetXFormsPage(XFormsPage* _pPage)
268 m_pXFormsPage = _pPage;
271 void DataTreeListBox::SetToolBoxItemIds(sal_uInt16 _nAddId,
272 sal_uInt16 _nAddElementId,
273 sal_uInt16 _nAddAttributeId,
274 sal_uInt16 _nEditId,
275 sal_uInt16 _nRemoveId)
277 m_nAddId = _nAddId;
278 m_nAddElementId = _nAddElementId;
279 m_nAddAttributeId = _nAddAttributeId;
280 m_nEditId = _nEditId;
281 m_nRemoveId = _nRemoveId;
284 void DataTreeListBox::DeleteAndClear()
286 sal_uIntPtr i, nCount = GetEntryCount();
287 for ( i = 0; i < nCount; ++i )
289 SvTreeListEntry* pEntry = GetEntry(i);
290 if ( pEntry )
291 delete static_cast< ItemNode* >( pEntry->GetUserData() );
294 Clear();
298 // class XFormsPage
300 VCL_BUILDER_FACTORY_ARGS(DataTreeListBox, WB_BORDER)
302 XFormsPage::XFormsPage( vcl::Window* pParent, DataNavigatorWindow* _pNaviWin, DataGroupType _eGroup ) :
304 TabPage( pParent, "XFormsPage", "svx/ui/xformspage.ui" ),
305 m_pNaviWin ( _pNaviWin ),
306 m_bHasModel ( false ),
307 m_eGroup ( _eGroup ),
308 m_TbxImageList ( SVX_RES( RID_SVXIMGLIST_XFORMS_TBX ) ),
309 m_bLinkOnce ( false )
312 get(m_pToolBox, "toolbar");
313 get(m_pItemList, "items");
314 Size aSize(LogicToPixel(Size(63, 100), MAP_APPFONT));
315 m_pItemList->set_width_request(aSize.Width());
316 m_pItemList->set_height_request(aSize.Height());
318 m_pItemList->SetGroup(_eGroup);
319 m_pItemList->SetXFormsPage( this );
321 m_nAddId = m_pToolBox->GetItemId("TBI_ITEM_ADD");
322 m_nAddElementId = m_pToolBox->GetItemId("TBI_ITEM_ADD_ELEMENT");
323 m_nAddAttributeId = m_pToolBox->GetItemId("TBI_ITEM_ADD_ATTRIBUTE");
324 m_nEditId = m_pToolBox->GetItemId("TBI_ITEM_EDIT");
325 m_nRemoveId = m_pToolBox->GetItemId("TBI_ITEM_REMOVE");
327 m_pItemList->SetToolBoxItemIds(m_nAddId, m_nAddElementId, m_nAddAttributeId, m_nEditId, m_nRemoveId);
329 const ImageList& rImageList = m_TbxImageList;
330 m_pToolBox->InsertSeparator(4,5);
331 m_pToolBox->SetItemImage( m_nAddId, rImageList.GetImage( IID_ITEM_ADD ) );
332 m_pToolBox->SetItemImage( m_nAddElementId, rImageList.GetImage( IID_ITEM_ADD_ELEMENT ) );
333 m_pToolBox->SetItemImage( m_nAddAttributeId, rImageList.GetImage( IID_ITEM_ADD_ATTRIBUTE ) );
334 m_pToolBox->SetItemImage( m_nEditId, rImageList.GetImage( IID_ITEM_EDIT ) );
335 m_pToolBox->SetItemImage( m_nRemoveId, rImageList.GetImage( IID_ITEM_REMOVE ) );
337 if ( DGTInstance == m_eGroup )
338 m_pToolBox->RemoveItem( m_pToolBox->GetItemPos( m_nAddId ) );
339 else
341 m_pToolBox->RemoveItem( m_pToolBox->GetItemPos( m_nAddElementId ) );
342 m_pToolBox->RemoveItem( m_pToolBox->GetItemPos( m_nAddAttributeId ) );
344 if ( DGTSubmission == m_eGroup )
346 m_pToolBox->SetItemText( m_nAddId, SVX_RESSTR( RID_STR_DATANAV_ADD_SUBMISSION ) );
347 m_pToolBox->SetItemText( m_nEditId, SVX_RESSTR( RID_STR_DATANAV_EDIT_SUBMISSION ) );
348 m_pToolBox->SetItemText( m_nRemoveId, SVX_RESSTR( RID_STR_DATANAV_REMOVE_SUBMISSION ) );
350 else
352 m_pToolBox->SetItemText( m_nAddId, SVX_RESSTR( RID_STR_DATANAV_ADD_BINDING ) );
353 m_pToolBox->SetItemText( m_nEditId, SVX_RESSTR( RID_STR_DATANAV_EDIT_BINDING ) );
354 m_pToolBox->SetItemText( m_nRemoveId, SVX_RESSTR( RID_STR_DATANAV_REMOVE_BINDING ) );
358 const Size aTbxSz( m_pToolBox->CalcWindowSizePixel() );
359 m_pToolBox->SetSizePixel( aTbxSz );
360 m_pToolBox->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
361 m_pToolBox->SetSelectHdl( LINK( this, XFormsPage, TbxSelectHdl ) );
362 Point aPos = m_pItemList->GetPosPixel();
363 aPos.Y() = aTbxSz.Height();
364 m_pItemList->SetPosPixel( aPos );
366 m_pItemList->SetSelectHdl( LINK( this, XFormsPage, ItemSelectHdl ) );
367 m_pItemList->SetNodeDefaultImages();
368 WinBits nBits = WB_BORDER | WB_TABSTOP | WB_HIDESELECTION | WB_NOINITIALSELECTION;
369 if ( DGTInstance == m_eGroup || DGTSubmission == m_eGroup )
370 nBits |= WB_HASBUTTONS | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONSATROOT;
371 m_pItemList->SetStyle( m_pItemList->GetStyle() | nBits );
372 m_pItemList->Show();
373 ItemSelectHdl( m_pItemList );
376 XFormsPage::~XFormsPage()
378 disposeOnce();
381 void XFormsPage::dispose()
383 m_pToolBox.clear();
384 m_pItemList.clear();
385 m_pNaviWin.clear();
386 TabPage::dispose();
389 IMPL_LINK_NOARG_TYPED(XFormsPage, TbxSelectHdl, ToolBox *, void)
391 DoToolBoxAction( m_pToolBox->GetCurItemId() );
394 IMPL_LINK_NOARG(XFormsPage, ItemSelectHdl)
396 EnableMenuItems( NULL );
397 return 0;
400 void XFormsPage::AddChildren(
401 SvTreeListEntry* _pParent, const ImageList& _rImgLst,
402 const Reference< css::xml::dom::XNode >& _xNode )
404 DBG_ASSERT( m_xUIHelper.is(), "XFormsPage::AddChildren(): invalid UIHelper" );
408 Reference< css::xml::dom::XNodeList > xNodeList = _xNode->getChildNodes();
409 if ( xNodeList.is() )
411 bool bShowDetails = m_pNaviWin->IsShowDetails();
412 sal_Int32 i, nNodeCount = xNodeList->getLength();
413 for ( i = 0; i < nNodeCount; ++i )
415 Reference< css::xml::dom::XNode > xChild = xNodeList->item(i);
416 css::xml::dom::NodeType eChildType = xChild->getNodeType();
417 Image aExpImg, aCollImg;
418 switch ( eChildType )
420 case css::xml::dom::NodeType_ATTRIBUTE_NODE:
421 aExpImg = aCollImg = _rImgLst.GetImage( IID_ATTRIBUTE );
422 break;
423 case css::xml::dom::NodeType_ELEMENT_NODE:
424 aExpImg = aCollImg = _rImgLst.GetImage( IID_ELEMENT );
425 break;
426 case css::xml::dom::NodeType_TEXT_NODE:
427 aExpImg = aCollImg = _rImgLst.GetImage( IID_TEXT );
428 break;
429 default:
430 aExpImg = aCollImg = _rImgLst.GetImage( IID_OTHER );
433 OUString sName = m_xUIHelper->getNodeDisplayName( xChild, bShowDetails );
434 if ( !sName.isEmpty() )
436 ItemNode* pNode = new ItemNode( xChild );
437 SvTreeListEntry* pEntry = m_pItemList->InsertEntry(
438 sName, aExpImg, aCollImg, _pParent, false, TREELIST_APPEND, pNode );
439 if ( xChild->hasAttributes() )
441 Reference< css::xml::dom::XNamedNodeMap > xMap = xChild->getAttributes();
442 if ( xMap.is() )
444 aExpImg = aCollImg = _rImgLst.GetImage( IID_ATTRIBUTE );
445 sal_Int32 j, nMapLen = xMap->getLength();
446 for ( j = 0; j < nMapLen; ++j )
448 Reference< css::xml::dom::XNode > xAttr = xMap->item(j);
449 pNode = new ItemNode( xAttr );
450 OUString sAttrName =
451 m_xUIHelper->getNodeDisplayName( xAttr, bShowDetails );
452 m_pItemList->InsertEntry(
453 sAttrName, aExpImg, aCollImg,
454 pEntry, false, TREELIST_APPEND, pNode );
458 if ( xChild->hasChildNodes() )
459 AddChildren( pEntry, _rImgLst, xChild );
464 catch( Exception& )
466 DBG_UNHANDLED_EXCEPTION();
470 bool XFormsPage::DoToolBoxAction( sal_uInt16 _nToolBoxID ) {
472 bool bHandled = false;
473 bool bIsDocModified = false;
474 m_pNaviWin->DisableNotify( true );
476 if(_nToolBoxID == m_nAddId || _nToolBoxID == m_nAddElementId || _nToolBoxID == m_nAddAttributeId)
478 bHandled = true;
479 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
480 DBG_ASSERT( xModel.is(), "XFormsPage::DoToolBoxAction(): Action without model" );
481 if ( DGTSubmission == m_eGroup )
483 ScopedVclPtrInstance< AddSubmissionDialog > aDlg( this, nullptr, m_xUIHelper );
484 if ( aDlg->Execute() == RET_OK && aDlg->GetNewSubmission().is() )
488 Reference< css::xforms::XSubmission > xNewSubmission = aDlg->GetNewSubmission();
489 Reference< XSet > xSubmissions( xModel->getSubmissions(), UNO_QUERY );
490 xSubmissions->insert( makeAny( xNewSubmission ) );
491 Reference< XPropertySet > xNewPropSet( xNewSubmission, UNO_QUERY );
492 SvTreeListEntry* pEntry = AddEntry( xNewPropSet );
493 m_pItemList->Select( pEntry, true );
494 bIsDocModified = true;
496 catch ( Exception& )
498 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while adding submission" );
502 else
504 DataItemType eType = DITElement;
505 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
506 ItemNode* pNode = NULL;
507 Reference< css::xml::dom::XNode > xParentNode;
508 Reference< XPropertySet > xNewBinding;
509 sal_uInt16 nResId = 0;
510 bool bIsElement = true;
511 if ( DGTInstance == m_eGroup )
513 if ( !m_sInstanceURL.isEmpty() )
515 ScopedVclPtrInstance< LinkedInstanceWarningBox > aMsgBox( this );
516 if ( aMsgBox->Execute() != RET_OK )
517 return bHandled;
520 DBG_ASSERT( pEntry, "XFormsPage::DoToolBoxAction(): no entry" );
521 ItemNode* pParentNode = static_cast< ItemNode* >( pEntry->GetUserData() );
522 DBG_ASSERT( pParentNode, "XFormsPage::DoToolBoxAction(): no parent node" );
523 xParentNode = pParentNode->m_xNode;
524 Reference< css::xml::dom::XNode > xNewNode;
525 if ( m_nAddElementId == _nToolBoxID )
529 nResId = RID_STR_DATANAV_ADD_ELEMENT;
530 xNewNode = m_xUIHelper->createElement( xParentNode, NEW_ELEMENT );
532 catch ( Exception& )
534 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create element" );
537 else
539 nResId = RID_STR_DATANAV_ADD_ATTRIBUTE;
540 bIsElement = false;
541 eType = DITAttribute;
544 xNewNode = m_xUIHelper->createAttribute( xParentNode, NEW_ATTRIBUTE );
546 catch ( Exception& )
548 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create attribute" );
554 xNewNode = xParentNode->appendChild( xNewNode );
556 catch ( css::xml::dom::DOMException& e )
558 if ( e.Code == css::xml::dom::DOMExceptionType_DOMSTRING_SIZE_ERR )
560 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): domexception: size error" );
562 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): domexception while append child" );
564 catch ( Exception& )
566 SAL_WARN( "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& )
580 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
585 m_xUIHelper->getBindingForNode( xNewNode, sal_True );
587 catch ( Exception& )
589 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while get binding for node" );
591 pNode = new ItemNode( xNewNode );
593 else
597 nResId = RID_STR_DATANAV_ADD_BINDING;
598 xNewBinding = xModel->createBinding();
599 Reference< XSet > xBindings( xModel->getBindings(), UNO_QUERY );
600 xBindings->insert( makeAny( xNewBinding ) );
601 pNode = new ItemNode( xNewBinding );
602 eType = DITBinding;
604 catch ( Exception& )
606 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while adding binding" );
610 ScopedVclPtrInstance< AddDataItemDialog > aDlg( this, pNode, m_xUIHelper );
611 aDlg->SetText( SVX_RESSTR( nResId ) );
612 aDlg->InitText( eType );
613 short nReturn = aDlg->Execute();
614 if ( DGTInstance == m_eGroup )
616 if ( RET_OK == nReturn )
618 SvTreeListEntry* pNewEntry = AddEntry( pNode, bIsElement );
619 m_pItemList->MakeVisible( pNewEntry );
620 m_pItemList->Select( pNewEntry, true );
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" );
633 delete pNode;
635 catch ( Exception& )
637 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
641 else
643 if ( RET_OK == nReturn )
645 SvTreeListEntry* pNewEntry = AddEntry( xNewBinding );
646 m_pItemList->Select( pNewEntry, true );
647 bIsDocModified = true;
649 else
653 Reference< XSet > xBindings( xModel->getBindings(), UNO_QUERY );
654 xBindings->remove( makeAny( xNewBinding ) );
656 catch ( Exception& )
658 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
661 delete pNode;
665 else if(_nToolBoxID == m_nEditId)
667 bHandled = true;
668 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
669 if ( pEntry )
671 if ( DGTSubmission == m_eGroup && m_pItemList->GetParent( pEntry ) )
672 pEntry = m_pItemList->GetParent( pEntry );
673 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
674 if ( DGTInstance == m_eGroup || DGTBinding == m_eGroup )
676 if ( DGTInstance == m_eGroup && !m_sInstanceURL.isEmpty() )
678 ScopedVclPtrInstance< LinkedInstanceWarningBox > aMsgBox( this );
679 if ( aMsgBox->Execute() != RET_OK )
680 return bHandled;
683 ScopedVclPtrInstance< AddDataItemDialog > aDlg( this, pNode, m_xUIHelper );
684 DataItemType eType = DITElement;
685 sal_uInt16 nResId = RID_STR_DATANAV_EDIT_ELEMENT;
686 if ( pNode && pNode->m_xNode.is() )
690 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
691 if ( eChildType == css::xml::dom::NodeType_ATTRIBUTE_NODE )
693 nResId = RID_STR_DATANAV_EDIT_ATTRIBUTE;
694 eType = DITAttribute;
697 catch ( Exception& )
699 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
702 else if ( DGTBinding == m_eGroup )
704 nResId = RID_STR_DATANAV_EDIT_BINDING;
705 eType = DITBinding;
707 aDlg->SetText( SVX_RESSTR( nResId ) );
708 aDlg->InitText( eType );
709 if ( aDlg->Execute() == RET_OK )
711 // Set the new name
712 OUString sNewName;
713 if ( DGTInstance == m_eGroup )
717 sNewName = m_xUIHelper->getNodeDisplayName(
718 pNode->m_xNode, m_pNaviWin->IsShowDetails() );
720 catch ( Exception& )
722 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
725 else
729 OUString sDelim( ": " );
730 OUString sTemp;
731 pNode->m_xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
732 sNewName += sTemp;
733 sNewName += sDelim;
734 pNode->m_xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
735 sNewName += sTemp;
737 catch ( Exception& )
739 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
743 m_pItemList->SetEntryText( pEntry, sNewName );
744 bIsDocModified = true;
747 else
749 ScopedVclPtrInstance< AddSubmissionDialog > aDlg( this, pNode, m_xUIHelper );
750 aDlg->SetText( SVX_RESSTR( RID_STR_DATANAV_EDIT_SUBMISSION ) );
751 if ( aDlg->Execute() == RET_OK )
753 EditEntry( pNode->m_xPropSet );
754 bIsDocModified = true;
759 else if(_nToolBoxID == m_nRemoveId)
761 bHandled = true;
762 if ( DGTInstance == m_eGroup && !m_sInstanceURL.isEmpty() )
764 ScopedVclPtrInstance< LinkedInstanceWarningBox > aMsgBox( this );
765 if ( aMsgBox->Execute() != RET_OK )
766 return bHandled;
768 bIsDocModified = RemoveEntry();
770 else if(_nToolBoxID == MID_INSERT_CONTROL)
772 OSL_FAIL( "XFormsPage::DoToolboxAction: MID_INSERT_CONTROL not implemented, yet!" );
774 else
776 OSL_FAIL( "XFormsPage::DoToolboxAction: unknown ID!" );
779 m_pNaviWin->DisableNotify( false );
780 EnableMenuItems( NULL );
781 if ( bIsDocModified )
782 svxform::DataNavigatorWindow::SetDocModified();
783 return bHandled;
787 SvTreeListEntry* XFormsPage::AddEntry( ItemNode* _pNewNode, bool _bIsElement )
789 SvTreeListEntry* pParent = m_pItemList->FirstSelected();
790 const ImageList& rImageList = m_pNaviWin->GetItemImageList();
791 sal_uInt16 nImageID = ( _bIsElement ) ? IID_ELEMENT : IID_ATTRIBUTE;
792 Image aImage = rImageList.GetImage( nImageID );
793 OUString sName;
796 sName = m_xUIHelper->getNodeDisplayName(
797 _pNewNode->m_xNode, m_pNaviWin->IsShowDetails() );
799 catch ( Exception& )
801 DBG_UNHANDLED_EXCEPTION();
803 return m_pItemList->InsertEntry(
804 sName, aImage, aImage, pParent, false, TREELIST_APPEND, _pNewNode );
808 SvTreeListEntry* XFormsPage::AddEntry( const Reference< XPropertySet >& _rEntry )
810 SvTreeListEntry* pEntry = NULL;
811 const ImageList& rImageList = m_pNaviWin->GetItemImageList();
812 Image aImage = rImageList.GetImage( IID_ELEMENT );
814 ItemNode* pNode = new ItemNode( _rEntry );
815 OUString sTemp;
817 if ( DGTSubmission == m_eGroup )
821 // ID
822 _rEntry->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
823 pEntry = m_pItemList->InsertEntry( sTemp, aImage, aImage, NULL, false, TREELIST_APPEND, pNode );
824 // Action
825 _rEntry->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp;
826 OUString sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_ACTION );
827 sEntry += sTemp;
828 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
829 // Method
830 _rEntry->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp;
831 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_METHOD );
832 sEntry += m_aMethodString.toUI( sTemp );
833 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
834 // Ref
835 _rEntry->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp;
836 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_REF );
837 sEntry += sTemp;
838 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
839 // Bind
840 _rEntry->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp;
841 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_BIND );
842 sEntry += sTemp;
843 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
844 // Replace
845 _rEntry->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp;
846 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_REPLACE );
847 sEntry += m_aReplaceString.toUI( sTemp );
848 m_pItemList->InsertEntry( sEntry, aImage, aImage, pEntry );
850 catch ( Exception& )
852 SAL_WARN( "svx.form", "XFormsPage::AddEntry(Ref): exception caught" );
855 else // then Binding Page
859 OUString sDelim( ": " );
860 OUString sName;
861 _rEntry->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
862 sName += sTemp;
863 sName += sDelim;
864 _rEntry->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
865 sName += sTemp;
866 pEntry = m_pItemList->InsertEntry(
867 sName, aImage, aImage, NULL, false, TREELIST_APPEND, pNode );
869 catch ( Exception& )
871 SAL_WARN( "svx.form", "XFormsPage::AddEntry(Ref): exception caught" );
875 return pEntry;
879 void XFormsPage::EditEntry( const Reference< XPropertySet >& _rEntry )
881 OUString sTemp;
883 if ( DGTSubmission == m_eGroup )
887 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
889 // #i36262# may be called for submission entry *or* for
890 // submission children. If we don't have any children, we
891 // assume the latter case and use the parent
892 if( m_pItemList->GetEntry( pEntry, 0 ) == NULL )
894 pEntry = m_pItemList->GetModel()->GetParent( pEntry );
897 _rEntry->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
898 m_pItemList->SetEntryText( pEntry, sTemp );
900 _rEntry->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp;
901 OUString sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_BIND );
902 sEntry += sTemp;
903 sal_uIntPtr nPos = 0;
904 SvTreeListEntry* pChild = m_pItemList->GetEntry( pEntry, nPos++ );
905 m_pItemList->SetEntryText( pChild, sEntry );
906 _rEntry->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp;
907 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_REF );
908 sEntry += sTemp;
909 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
910 m_pItemList->SetEntryText( pChild, sEntry );
911 _rEntry->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp;
912 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_ACTION );
913 sEntry += sTemp;
914 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
915 m_pItemList->SetEntryText( pChild, sEntry );
916 _rEntry->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp;
917 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_METHOD );
918 sEntry += m_aMethodString.toUI( sTemp );
919 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
920 m_pItemList->SetEntryText( pChild, sEntry );
921 _rEntry->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp;
922 sEntry = SVX_RESSTR( RID_STR_DATANAV_SUBM_REPLACE );
923 sEntry += m_aReplaceString.toUI( sTemp );
924 pChild = m_pItemList->GetEntry( pEntry, nPos++ );
925 m_pItemList->SetEntryText( pChild, sEntry );
927 catch ( Exception& )
929 SAL_WARN( "svx.form", "XFormsPage::EditEntry(): exception caught" );
935 bool XFormsPage::RemoveEntry()
937 bool bRet = false;
938 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
939 if ( pEntry &&
940 ( DGTInstance != m_eGroup || m_pItemList->GetParent( pEntry ) ) )
942 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
943 DBG_ASSERT( xModel.is(), "XFormsPage::RemoveEntry(): no model" );
944 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
945 DBG_ASSERT( pNode, "XFormsPage::RemoveEntry(): no node" );
947 if ( DGTInstance == m_eGroup )
951 DBG_ASSERT( pNode->m_xNode.is(), "XFormsPage::RemoveEntry(): no XNode" );
952 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
953 bool bIsElement = ( eChildType == css::xml::dom::NodeType_ELEMENT_NODE );
954 sal_uInt16 nResId = bIsElement ? RID_STR_QRY_REMOVE_ELEMENT : RID_STR_QRY_REMOVE_ATTRIBUTE;
955 OUString sVar = bIsElement ? OUString(ELEMENTNAME) : OUString(ATTRIBUTENAME);
956 ScopedVclPtrInstance< MessageDialog > aQBox(this, SVX_RES(nResId), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
957 OUString sMessText = aQBox->get_primary_text();
958 sMessText = sMessText.replaceFirst(
959 sVar, m_xUIHelper->getNodeDisplayName( pNode->m_xNode, sal_False ) );
960 aQBox->set_primary_text(sMessText);
961 if ( aQBox->Execute() == RET_YES )
963 SvTreeListEntry* pParent = m_pItemList->GetParent( pEntry );
964 DBG_ASSERT( pParent, "XFormsPage::RemoveEntry(): no parent entry" );
965 ItemNode* pParentNode = static_cast< ItemNode* >( pParent->GetUserData() );
966 DBG_ASSERT( pParentNode && pParentNode->m_xNode.is(), "XFormsPage::RemoveEntry(): no parent XNode" );
968 Reference< css::xml::dom::XNode > xPNode;
969 Reference< css::xml::dom::XNode > xNode =
970 pParentNode->m_xNode->removeChild( pNode->m_xNode );
971 if ( xNode.is() )
972 xPNode = xNode->getParentNode();
973 DBG_ASSERT( !xPNode.is(), "XFormsPage::RemoveEntry(): node not removed" );
974 bRet = true;
977 catch ( Exception& )
979 SAL_WARN( "svx.form", "XFormsPage::RemoveEntry(): exception caught" );
982 else
984 DBG_ASSERT( pNode->m_xPropSet.is(), "XFormsPage::RemoveEntry(): no propset" );
985 bool bSubmission = ( DGTSubmission == m_eGroup );
986 sal_uInt16 nResId = bSubmission ? RID_STR_QRY_REMOVE_SUBMISSION : RID_STR_QRY_REMOVE_BINDING;
987 OUString sProperty = bSubmission ? OUString(PN_SUBMISSION_ID) : OUString(PN_BINDING_ID);
988 OUString sSearch = bSubmission ? OUString(SUBMISSIONNAME) : OUString(BINDINGNAME);
989 OUString sName;
992 pNode->m_xPropSet->getPropertyValue( sProperty ) >>= sName;
994 catch ( Exception& )
996 SAL_WARN( "svx.form", "XFormsPage::RemoveEntry(): exception caught" );
998 ScopedVclPtrInstance<MessageDialog> aQBox(this, SVX_RES(nResId),
999 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
1000 OUString sMessText = aQBox->get_primary_text();
1001 sMessText = sMessText.replaceFirst( sSearch, sName);
1002 aQBox->set_primary_text(sMessText);
1003 if ( aQBox->Execute() == RET_YES )
1007 if ( bSubmission )
1008 xModel->getSubmissions()->remove( makeAny( pNode->m_xPropSet ) );
1009 else // then Binding Page
1010 xModel->getBindings()->remove( makeAny( pNode->m_xPropSet ) );
1011 bRet = true;
1013 catch ( Exception& )
1015 SAL_WARN( "svx.form", "XFormsPage::RemoveEntry(): exception caught" );
1020 if ( bRet )
1021 m_pItemList->RemoveEntry( pEntry );
1024 return bRet;
1028 bool XFormsPage::Notify( NotifyEvent& rNEvt )
1030 bool nHandled = false;
1032 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
1034 sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
1036 switch ( nCode )
1038 case KEY_DELETE:
1039 nHandled = DoMenuAction( m_nRemoveId );
1040 break;
1044 return nHandled || Window::Notify( rNEvt );
1047 void XFormsPage::Resize()
1049 Size aSize = GetOutputSizePixel();
1050 Size aTbxSize = m_pToolBox->GetSizePixel();
1051 aTbxSize.Width() = aSize.Width();
1052 m_pToolBox->SetSizePixel( aTbxSize );
1053 aSize.Width() -= 4;
1054 aSize.Height() -= ( 4 + aTbxSize.Height() );
1055 m_pItemList->SetPosSizePixel( Point( 2, 2 + aTbxSize.Height() ), aSize );
1058 OUString XFormsPage::SetModel( const Reference< css::xforms::XModel >& _xModel, sal_uInt16 _nPagePos )
1060 DBG_ASSERT( _xModel.is(), "XFormsPage::SetModel(): invalid model" );
1062 m_xUIHelper = Reference< css::xforms::XFormsUIHelper1 >( _xModel, UNO_QUERY );
1063 OUString sRet;
1064 m_bHasModel = true;
1065 const ImageList& rImageList = m_pNaviWin->GetItemImageList();
1067 switch ( m_eGroup )
1069 case DGTInstance :
1071 DBG_ASSERT( _nPagePos != TAB_PAGE_NOTFOUND, "XFormsPage::SetModel(): invalid page position" );
1074 Reference< XContainer > xContainer( _xModel->getInstances(), UNO_QUERY );
1075 if ( xContainer.is() )
1076 m_pNaviWin->AddContainerBroadcaster( xContainer );
1078 Reference< XEnumerationAccess > xNumAccess( _xModel->getInstances(), UNO_QUERY );
1079 if ( xNumAccess.is() )
1081 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1082 if ( xNum.is() && xNum->hasMoreElements() )
1084 sal_uInt16 nIter = 0;
1085 while ( xNum->hasMoreElements() )
1087 if ( nIter == _nPagePos )
1089 Sequence< PropertyValue > xPropSeq;
1090 Any aAny = xNum->nextElement();
1091 if ( aAny >>= xPropSeq )
1092 sRet = LoadInstance( xPropSeq, rImageList );
1093 else
1095 SAL_WARN( "svx.form", "XFormsPage::SetModel(): invalid instance" );
1097 break;
1099 else
1101 xNum->nextElement();
1102 nIter++;
1108 catch( Exception& )
1110 SAL_WARN( "svx.form", "XFormsPage::SetModel(): exception caught" );
1112 break;
1115 case DGTSubmission :
1117 DBG_ASSERT( TAB_PAGE_NOTFOUND == _nPagePos, "XFormsPage::SetModel(): invalid page position" );
1120 Reference< XContainer > xContainer( _xModel->getSubmissions(), UNO_QUERY );
1121 if ( xContainer.is() )
1122 m_pNaviWin->AddContainerBroadcaster( xContainer );
1124 Reference< XEnumerationAccess > xNumAccess( _xModel->getSubmissions(), UNO_QUERY );
1125 if ( xNumAccess.is() )
1127 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1128 if ( xNum.is() && xNum->hasMoreElements() )
1130 while ( xNum->hasMoreElements() )
1132 Reference< XPropertySet > xPropSet;
1133 Any aAny = xNum->nextElement();
1134 if ( aAny >>= xPropSet )
1135 AddEntry( xPropSet );
1140 catch( Exception& )
1142 SAL_WARN( "svx.form", "XFormsPage::SetModel(): exception caught" );
1144 break;
1147 case DGTBinding :
1149 DBG_ASSERT( TAB_PAGE_NOTFOUND == _nPagePos, "XFormsPage::SetModel(): invalid page position" );
1152 Reference< XContainer > xContainer( _xModel->getBindings(), UNO_QUERY );
1153 if ( xContainer.is() )
1154 m_pNaviWin->AddContainerBroadcaster( xContainer );
1156 Reference< XEnumerationAccess > xNumAccess( _xModel->getBindings(), UNO_QUERY );
1157 if ( xNumAccess.is() )
1159 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1160 if ( xNum.is() && xNum->hasMoreElements() )
1162 Image aImage1 = rImageList.GetImage( IID_ELEMENT );
1163 Image aImage2 = rImageList.GetImage( IID_ELEMENT );
1164 OUString sDelim( ": " );
1165 while ( xNum->hasMoreElements() )
1167 Reference< XPropertySet > xPropSet;
1168 Any aAny = xNum->nextElement();
1169 if ( aAny >>= xPropSet )
1171 OUString sEntry;
1172 OUString sTemp;
1173 xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
1174 sEntry += sTemp;
1175 sEntry += sDelim;
1176 xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
1177 sEntry += sTemp;
1179 ItemNode* pNode = new ItemNode( xPropSet );
1180 m_pItemList->InsertEntry(
1181 sEntry, aImage1, aImage2, NULL, false, TREELIST_APPEND, pNode );
1187 catch( Exception& )
1189 SAL_WARN( "svx.form", "XFormsPage::SetModel(): exception caught" );
1191 break;
1193 default:
1194 OSL_FAIL( "XFormsPage::SetModel: unknown group!" );
1195 break;
1198 EnableMenuItems( NULL );
1200 return sRet;
1203 void XFormsPage::ClearModel()
1205 m_bHasModel = false;
1206 m_pItemList->DeleteAndClear();
1209 OUString XFormsPage::LoadInstance(
1210 const Sequence< PropertyValue >& _xPropSeq, const ImageList& _rImgLst )
1212 OUString sRet;
1213 OUString sTemp;
1214 OUString sInstModel = PN_INSTANCE_MODEL;
1215 OUString sInstName = PN_INSTANCE_ID;
1216 OUString sInstURL = PN_INSTANCE_URL;
1217 const PropertyValue* pProps = _xPropSeq.getConstArray();
1218 const PropertyValue* pPropsEnd = pProps + _xPropSeq.getLength();
1219 for ( ; pProps != pPropsEnd; ++pProps )
1221 if ( sInstModel == pProps->Name )
1223 Reference< css::xml::dom::XNode > xRoot;
1224 if ( pProps->Value >>= xRoot )
1228 Reference< XEventTarget > xTarget( xRoot, UNO_QUERY );
1229 if ( xTarget.is() )
1230 m_pNaviWin->AddEventBroadcaster( xTarget );
1232 #if OSL_DEBUG_LEVEL > 0
1233 css::xml::dom::NodeType eNodeType = xRoot->getNodeType(); (void)eNodeType;
1234 #endif
1235 OUString sNodeName =
1236 m_xUIHelper->getNodeDisplayName( xRoot, m_pNaviWin->IsShowDetails() );
1237 if ( sNodeName.isEmpty() )
1238 sNodeName = xRoot->getNodeName();
1239 if ( xRoot->hasChildNodes() )
1240 AddChildren( NULL, _rImgLst, xRoot );
1242 catch ( Exception& )
1244 SAL_WARN( "svx.form", "XFormsPage::LoadInstance(): exception caught" );
1248 else if ( sInstName == pProps->Name && ( pProps->Value >>= sTemp ) )
1249 m_sInstanceName = sRet = sTemp;
1250 else if ( sInstURL == pProps->Name && ( pProps->Value >>= sTemp ) )
1251 m_sInstanceURL = sTemp;
1254 return sRet;
1258 bool XFormsPage::DoMenuAction( sal_uInt16 _nMenuID )
1260 return DoToolBoxAction( _nMenuID );
1264 void XFormsPage::EnableMenuItems( Menu* _pMenu )
1266 bool bEnableAdd = false;
1267 bool bEnableEdit = false;
1268 bool bEnableRemove = false;
1270 SvTreeListEntry* pEntry = m_pItemList->FirstSelected();
1271 if ( pEntry )
1273 bEnableAdd = true;
1274 bool bSubmitChild = false;
1275 if ( DGTSubmission == m_eGroup && m_pItemList->GetParent( pEntry ) )
1277 pEntry = m_pItemList->GetParent( pEntry );
1278 bSubmitChild = true;
1280 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
1281 if ( pNode && ( pNode->m_xNode.is() || pNode->m_xPropSet.is() ) )
1283 bEnableEdit = true;
1284 bEnableRemove = !bSubmitChild;
1285 if ( DGTInstance == m_eGroup && !m_pItemList->GetParent( pEntry ) )
1286 bEnableRemove = false;
1287 if ( pNode->m_xNode.is() )
1291 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
1292 if ( eChildType != css::xml::dom::NodeType_ELEMENT_NODE
1293 && eChildType != css::xml::dom::NodeType_DOCUMENT_NODE )
1295 bEnableAdd = false;
1298 catch ( Exception& )
1300 SAL_WARN( "svx.form", "XFormsPage::EnableMenuItems(): exception caught" );
1305 else if ( m_eGroup != DGTInstance )
1306 bEnableAdd = true;
1308 m_pToolBox->EnableItem( m_nAddId, bEnableAdd );
1309 m_pToolBox->EnableItem( m_nAddElementId, bEnableAdd );
1310 m_pToolBox->EnableItem( m_nAddAttributeId, bEnableAdd );
1311 m_pToolBox->EnableItem( m_nEditId, bEnableEdit );
1312 m_pToolBox->EnableItem( m_nRemoveId, bEnableRemove );
1314 if ( _pMenu )
1316 _pMenu->EnableItem( m_nAddId, bEnableAdd );
1317 _pMenu->EnableItem( m_nAddElementId, bEnableAdd );
1318 _pMenu->EnableItem( m_nAddAttributeId, bEnableAdd );
1319 _pMenu->EnableItem( m_nEditId, bEnableEdit );
1320 _pMenu->EnableItem( m_nRemoveId, bEnableRemove );
1322 if ( DGTInstance == m_eGroup )
1324 sal_uInt16 nResId1 = RID_STR_DATANAV_EDIT_ELEMENT;
1325 sal_uInt16 nResId2 = RID_STR_DATANAV_REMOVE_ELEMENT;
1326 if ( pEntry )
1328 ItemNode* pNode = static_cast< ItemNode* >( pEntry->GetUserData() );
1329 if ( pNode && pNode->m_xNode.is() )
1333 css::xml::dom::NodeType eChildType = pNode->m_xNode->getNodeType();
1334 if ( eChildType == css::xml::dom::NodeType_ATTRIBUTE_NODE )
1336 nResId1 = RID_STR_DATANAV_EDIT_ATTRIBUTE;
1337 nResId2 = RID_STR_DATANAV_REMOVE_ATTRIBUTE;
1340 catch ( Exception& )
1342 SAL_WARN( "svx.form", "XFormsPage::EnableMenuItems(): exception caught" );
1346 m_pToolBox->SetItemText( m_nEditId, SVX_RESSTR( nResId1 ) );
1347 m_pToolBox->SetItemText( m_nRemoveId, SVX_RESSTR( nResId2 ) );
1348 if ( _pMenu )
1350 _pMenu->SetItemText( m_nEditId, SVX_RESSTR( nResId1 ) );
1351 _pMenu->SetItemText( m_nRemoveId, SVX_RESSTR( nResId2 ) );
1356 DataNavigatorWindow::DataNavigatorWindow(vcl::Window* pParent, SfxBindings* pBindings)
1357 : Window(pParent)
1358 , m_pInstPage(NULL)
1359 , m_pSubmissionPage(NULL)
1360 , m_pBindingPage(NULL)
1361 , m_nLastSelectedPos(LISTBOX_ENTRY_NOTFOUND)
1362 , m_bShowDetails(false)
1363 , m_bIsNotifyDisabled(false)
1364 , m_aItemImageList(SVX_RES(RID_SVXIL_DATANAVI))
1365 , m_xDataListener(new DataListener(this))
1367 m_pUIBuilder = new VclBuilder(this, getUIRootDir(), "svx/ui/datanavigator.ui", "DataNavigator");
1368 get(m_pModelsBox, "modelslist");
1369 get(m_pModelBtn, "modelsbutton");
1370 get(m_pTabCtrl, "tabcontrol");
1371 get(m_pInstanceBtn, "instances");
1373 // handler
1374 m_pModelsBox->SetSelectHdl( LINK( this, DataNavigatorWindow, ModelSelectHdl ) );
1375 Link<MenuButton *, void> aLink1 = LINK( this, DataNavigatorWindow, MenuSelectHdl );
1376 m_pModelBtn->SetSelectHdl( aLink1 );
1377 m_pInstanceBtn->SetSelectHdl( aLink1 );
1378 Link<> aLink2 = LINK( this, DataNavigatorWindow, MenuActivateHdl );
1379 m_pModelBtn->SetActivateHdl( aLink2 );
1380 m_pInstanceBtn->SetActivateHdl( aLink2 );
1381 m_pTabCtrl->SetActivatePageHdl( LINK( this, DataNavigatorWindow, ActivatePageHdl ) );
1382 m_aUpdateTimer.SetTimeout( 2000 );
1383 m_aUpdateTimer.SetTimeoutHdl( LINK( this, DataNavigatorWindow, UpdateHdl ) );
1385 // init tabcontrol
1386 m_pTabCtrl->Show();
1387 sal_Int32 nPageId = m_pTabCtrl->GetPageId("instance");
1388 SvtViewOptions aViewOpt( E_TABDIALOG, CFGNAME_DATANAVIGATOR );
1389 if ( aViewOpt.Exists() )
1391 nPageId = aViewOpt.GetPageID();
1392 aViewOpt.GetUserItem(CFGNAME_SHOWDETAILS) >>= m_bShowDetails;
1395 Menu* pMenu = m_pInstanceBtn->GetPopupMenu();
1396 sal_uInt16 nInstancesDetailsId = pMenu->GetItemId("instancesdetails");
1397 pMenu->SetItemBits(nInstancesDetailsId, MenuItemBits::CHECKABLE );
1398 pMenu->CheckItem(nInstancesDetailsId, m_bShowDetails );
1400 m_pTabCtrl->SetCurPageId( static_cast< sal_uInt16 >( nPageId ) );
1401 ActivatePageHdl(m_pTabCtrl);
1403 // get our frame
1404 DBG_ASSERT( pBindings != NULL,
1405 "DataNavigatorWindow::LoadModels(): no SfxBindings; can't get frame" );
1406 m_xFrame = Reference<XFrame>(
1407 pBindings->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(),
1408 UNO_QUERY );
1409 DBG_ASSERT( m_xFrame.is(), "DataNavigatorWindow::LoadModels(): no frame" );
1410 // add frameaction listener
1411 Reference< XFrameActionListener > xListener(
1412 static_cast< XFrameActionListener* >( m_xDataListener.get() ), UNO_QUERY );
1413 m_xFrame->addFrameActionListener( xListener );
1415 // load xforms models of the current document
1416 LoadModels();
1419 DataNavigatorWindow::~DataNavigatorWindow()
1421 disposeOnce();
1424 void DataNavigatorWindow::dispose()
1426 SvtViewOptions aViewOpt( E_TABDIALOG, CFGNAME_DATANAVIGATOR );
1427 aViewOpt.SetPageID( static_cast< sal_Int32 >( m_pTabCtrl->GetCurPageId() ) );
1428 Any aAny;
1429 aAny <<= m_bShowDetails;
1430 aViewOpt.SetUserItem(CFGNAME_SHOWDETAILS,aAny);
1432 m_pInstPage.disposeAndClear();
1433 m_pSubmissionPage.disposeAndClear();
1434 m_pBindingPage.disposeAndClear();
1436 sal_Int32 i, nCount = m_aPageList.size();
1437 for ( i = 0; i < nCount; ++i )
1438 m_aPageList[i].disposeAndClear();
1439 m_aPageList.clear();
1441 Reference< XFrameActionListener > xListener(
1442 static_cast< XFrameActionListener* >( m_xDataListener.get() ), UNO_QUERY );
1443 m_xFrame->removeFrameActionListener( xListener );
1444 RemoveBroadcaster();
1445 m_xDataListener.clear();
1446 disposeBuilder();
1447 m_pModelsBox.clear();
1448 m_pModelBtn.clear();
1449 m_pTabCtrl.clear();
1450 m_pInstanceBtn.clear();
1451 vcl::Window::dispose();
1455 IMPL_LINK( DataNavigatorWindow, ModelSelectHdl, ListBox *, pBox )
1457 sal_Int32 nPos = m_pModelsBox->GetSelectEntryPos();
1458 // pBox == NULL, if you want to force a new fill.
1459 if ( nPos != m_nLastSelectedPos || !pBox )
1461 m_nLastSelectedPos = nPos;
1462 ClearAllPageModels( pBox != NULL );
1463 InitPages();
1464 SetPageModel();
1467 return 0;
1470 IMPL_LINK_TYPED( DataNavigatorWindow, MenuSelectHdl, MenuButton *, pBtn, void )
1472 bool bIsDocModified = false;
1473 Reference< css::xforms::XFormsUIHelper1 > xUIHelper;
1474 sal_Int32 nSelectedPos = m_pModelsBox->GetSelectEntryPos();
1475 OUString sSelectedModel( m_pModelsBox->GetEntry( nSelectedPos ) );
1476 Reference< css::xforms::XModel > xModel;
1479 Any aAny = m_xDataContainer->getByName( sSelectedModel );
1480 if ( aAny >>= xModel )
1481 xUIHelper = Reference< css::xforms::XFormsUIHelper1 >( xModel, UNO_QUERY );
1483 catch ( Exception& )
1485 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1487 DBG_ASSERT( xUIHelper.is(), "DataNavigatorWindow::MenuSelectHdl(): no UIHelper" );
1489 m_bIsNotifyDisabled = true;
1491 if (m_pModelBtn == pBtn)
1493 OString sIdent(pBtn->GetCurItemIdent());
1494 if (sIdent == "modelsadd")
1496 ScopedVclPtrInstance< AddModelDialog > aDlg( this, false );
1497 bool bShowDialog = true;
1498 while ( bShowDialog )
1500 bShowDialog = false;
1501 if ( aDlg->Execute() == RET_OK )
1503 OUString sNewName = aDlg->GetName();
1504 bool bDocumentData = aDlg->GetModifyDoc();
1506 if ( m_pModelsBox->GetEntryPos( sNewName ) != LISTBOX_ENTRY_NOTFOUND )
1508 // error: model name already exists
1509 ScopedVclPtrInstance< MessageDialog > aErrBox( this, SVX_RES( RID_STR_DOUBLE_MODELNAME ) );
1510 aErrBox->set_primary_text(aErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sNewName));
1511 aErrBox->Execute();
1512 bShowDialog = true;
1514 else
1518 // add new model to frame model
1519 Reference< css::xforms::XModel > xNewModel(
1520 xUIHelper->newModel( m_xFrameModel, sNewName ), UNO_SET_THROW );
1522 Reference< XPropertySet > xModelProps( xNewModel, UNO_QUERY_THROW );
1523 xModelProps->setPropertyValue(
1524 OUString( "ExternalData" ),
1525 makeAny( !bDocumentData ) );
1527 sal_Int32 nNewPos = m_pModelsBox->InsertEntry( sNewName );
1528 m_pModelsBox->SelectEntryPos( nNewPos );
1529 ModelSelectHdl(m_pModelsBox);
1530 bIsDocModified = true;
1532 catch ( Exception& )
1534 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1540 else if (sIdent == "modelsedit")
1542 ScopedVclPtrInstance< AddModelDialog > aDlg( this, true );
1543 aDlg->SetName( sSelectedModel );
1545 bool bDocumentData( false );
1548 Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY_THROW );
1549 Reference< XNameContainer > xXForms( xFormsSupp->getXForms(), UNO_SET_THROW );
1550 Reference< XPropertySet > xModelProps( xXForms->getByName( sSelectedModel ), UNO_QUERY_THROW );
1551 bool bExternalData = false;
1552 OSL_VERIFY( xModelProps->getPropertyValue(
1553 OUString( "ExternalData" ) ) >>= bExternalData );
1554 bDocumentData = !bExternalData;
1556 catch( const Exception& )
1558 DBG_UNHANDLED_EXCEPTION();
1560 aDlg->SetModifyDoc( bDocumentData );
1562 if ( aDlg->Execute() == RET_OK )
1564 if ( aDlg->GetModifyDoc() != bool( bDocumentData ) )
1566 bDocumentData = aDlg->GetModifyDoc();
1569 Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY_THROW );
1570 Reference< XNameContainer > xXForms( xFormsSupp->getXForms(), UNO_SET_THROW );
1571 Reference< XPropertySet > xModelProps( xXForms->getByName( sSelectedModel ), UNO_QUERY_THROW );
1572 xModelProps->setPropertyValue(
1573 OUString( "ExternalData" ),
1574 makeAny( !bDocumentData ) );
1575 bIsDocModified = true;
1577 catch( const Exception& )
1579 DBG_UNHANDLED_EXCEPTION();
1583 OUString sNewName = aDlg->GetName();
1584 if ( !sNewName.isEmpty() && ( sNewName != sSelectedModel ) )
1588 xUIHelper->renameModel( m_xFrameModel, sSelectedModel, sNewName );
1590 m_pModelsBox->RemoveEntry( nSelectedPos );
1591 nSelectedPos = m_pModelsBox->InsertEntry( sNewName );
1592 m_pModelsBox->SelectEntryPos( nSelectedPos );
1593 bIsDocModified = true;
1595 catch ( Exception& )
1597 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1602 else if (sIdent == "modelsremove")
1604 ScopedVclPtrInstance<MessageDialog> aQBox(this, SVX_RES( RID_STR_QRY_REMOVE_MODEL),
1605 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
1606 OUString sText = aQBox->get_primary_text();
1607 sText = sText.replaceFirst( MODELNAME, sSelectedModel );
1608 aQBox->set_primary_text(sText);
1609 if ( aQBox->Execute() == RET_YES )
1613 xUIHelper->removeModel( m_xFrameModel, sSelectedModel );
1615 catch ( Exception& )
1617 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1619 m_pModelsBox->RemoveEntry( nSelectedPos );
1620 if ( m_pModelsBox->GetEntryCount() <= nSelectedPos )
1621 nSelectedPos = m_pModelsBox->GetEntryCount() - 1;
1622 m_pModelsBox->SelectEntryPos( nSelectedPos );
1623 ModelSelectHdl(m_pModelsBox);
1624 bIsDocModified = true;
1627 else
1629 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong menu item" );
1632 else if (m_pInstanceBtn == pBtn)
1634 OString sIdent(pBtn->GetCurItemIdent());
1635 if (sIdent == "instancesadd")
1637 ScopedVclPtrInstance< AddInstanceDialog > aDlg( this, false );
1638 if ( aDlg->Execute() == RET_OK )
1640 sal_uInt16 nInst = GetNewPageId();
1641 OUString sName = aDlg->GetName();
1642 OUString sURL = aDlg->GetURL();
1643 bool bLinkOnce = aDlg->IsLinkInstance();
1646 Reference< css::xml::dom::XDocument > xNewInst =
1647 xUIHelper->newInstance( sName, sURL, !bLinkOnce );
1649 catch ( Exception& )
1651 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1653 ModelSelectHdl( NULL );
1654 m_pTabCtrl->SetCurPageId( nInst );
1655 XFormsPage* pPage = GetCurrentPage( nInst );
1656 pPage->SetInstanceName(sName);
1657 pPage->SetInstanceURL(sURL);
1658 pPage->SetLinkOnce(bLinkOnce);
1659 ActivatePageHdl(m_pTabCtrl);
1660 bIsDocModified = true;
1663 else if (sIdent == "instancesedit")
1665 sal_uInt16 nId = 0;
1666 XFormsPage* pPage = GetCurrentPage( nId );
1667 if ( pPage )
1669 ScopedVclPtrInstance< AddInstanceDialog > aDlg( this, true );
1670 aDlg->SetName( pPage->GetInstanceName() );
1671 aDlg->SetURL( pPage->GetInstanceURL() );
1672 aDlg->SetLinkInstance( pPage->GetLinkOnce() );
1673 OUString sOldName = aDlg->GetName();
1674 if ( aDlg->Execute() == RET_OK )
1676 OUString sNewName = aDlg->GetName();
1677 OUString sURL = aDlg->GetURL();
1678 bool bLinkOnce = aDlg->IsLinkInstance();
1681 xUIHelper->renameInstance( sOldName,
1682 sNewName,
1683 sURL,
1684 !bLinkOnce );
1686 catch ( Exception& )
1688 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1690 pPage->SetInstanceName(sNewName);
1691 pPage->SetInstanceURL(sURL);
1692 pPage->SetLinkOnce(bLinkOnce);
1693 m_pTabCtrl->SetPageText( nId, sNewName );
1694 bIsDocModified = true;
1698 else if (sIdent == "instancesremove")
1700 sal_uInt16 nId = 0;
1701 VclPtr<XFormsPage> pPage = GetCurrentPage( nId );
1702 if ( pPage )
1704 OUString sInstName = pPage->GetInstanceName();
1705 ScopedVclPtrInstance<MessageDialog> aQBox(this, SVX_RES(RID_STR_QRY_REMOVE_INSTANCE),
1706 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
1707 OUString sMessText = aQBox->get_primary_text();
1708 sMessText = sMessText.replaceFirst( INSTANCENAME, sInstName );
1709 aQBox->set_primary_text(sMessText);
1710 if ( aQBox->Execute() == RET_YES )
1712 bool bDoRemove = false;
1713 if (IsAdditionalPage(nId))
1715 PageList::iterator aPageListEnd = m_aPageList.end();
1716 PageList::iterator aFoundPage =
1717 std::find( m_aPageList.begin(), aPageListEnd, pPage );
1718 if ( aFoundPage != aPageListEnd )
1720 m_aPageList.erase( aFoundPage );
1721 pPage.disposeAndClear() ;
1722 bDoRemove = true;
1725 else
1727 m_pInstPage.disposeAndClear();
1728 bDoRemove = true;
1731 if ( bDoRemove )
1735 xUIHelper->removeInstance( sInstName );
1737 catch (const Exception&)
1739 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1741 m_pTabCtrl->RemovePage( nId );
1742 m_pTabCtrl->SetCurPageId(m_pTabCtrl->GetPageId("instance"));
1743 ModelSelectHdl( NULL );
1744 bIsDocModified = true;
1749 else if (sIdent == "instancesdetails")
1751 m_bShowDetails = !m_bShowDetails;
1752 PopupMenu* pMenu = m_pInstanceBtn->GetPopupMenu();
1753 pMenu->CheckItem(pMenu->GetItemId("instancesdetails"), m_bShowDetails );
1754 ModelSelectHdl(m_pModelsBox);
1756 else
1758 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong menu item" );
1761 else
1763 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong button" );
1766 m_bIsNotifyDisabled = false;
1768 if ( bIsDocModified )
1769 SetDocModified();
1772 bool DataNavigatorWindow::IsAdditionalPage(sal_uInt16 nId) const
1774 return m_pTabCtrl->GetPagePos(nId) >= 3;
1777 IMPL_LINK( DataNavigatorWindow, MenuActivateHdl, MenuButton *, pBtn )
1779 Menu* pMenu = pBtn->GetPopupMenu();
1781 if (m_pInstanceBtn == pBtn)
1783 sal_uInt16 nId(m_pTabCtrl->GetCurPageId());
1784 bool bIsInstPage = (IsAdditionalPage(nId) || m_pTabCtrl->GetPageName(nId) == "instance");
1785 pMenu->EnableItem( "instancesedit", bIsInstPage );
1786 pMenu->EnableItem( "instancesremove",
1787 bIsInstPage && m_pTabCtrl->GetPageCount() > MIN_PAGE_COUNT );
1788 pMenu->EnableItem( "instancesdetails", bIsInstPage );
1790 else if (m_pModelBtn == pBtn)
1792 // we need at least one model!
1793 pMenu->EnableItem("modelsremove", m_pModelsBox->GetEntryCount() > 1 );
1795 else
1797 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuActivateHdl(): wrong button" );
1799 return 0;
1802 IMPL_LINK_NOARG(DataNavigatorWindow, ActivatePageHdl)
1804 sal_uInt16 nId = 0;
1805 XFormsPage* pPage = GetCurrentPage( nId );
1806 if ( pPage )
1808 m_pTabCtrl->SetTabPage( nId, pPage );
1809 if ( m_xDataContainer.is() && !pPage->HasModel() )
1810 SetPageModel();
1813 return 0;
1816 IMPL_LINK_NOARG_TYPED(DataNavigatorWindow, UpdateHdl, Timer *, void)
1818 ModelSelectHdl( NULL );
1821 XFormsPage* DataNavigatorWindow::GetCurrentPage( sal_uInt16& rCurId )
1823 rCurId = m_pTabCtrl->GetCurPageId();
1824 XFormsPage* pPage = NULL;
1825 OString sName(m_pTabCtrl->GetPageName(rCurId));
1826 if (sName == "submissions")
1828 if ( !m_pSubmissionPage )
1829 m_pSubmissionPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTSubmission);
1830 pPage = m_pSubmissionPage;
1832 else if (sName == "bindings")
1834 if ( !m_pBindingPage )
1835 m_pBindingPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTBinding);
1836 pPage = m_pBindingPage;
1838 else if (sName == "instance")
1840 if ( !m_pInstPage )
1841 m_pInstPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTInstance);
1842 pPage = m_pInstPage;
1844 else
1846 sal_uInt16 nPos = m_pTabCtrl->GetPagePos( rCurId );
1847 if ( HasFirstInstancePage() && nPos > 0 )
1848 nPos--;
1849 if ( m_aPageList.size() > nPos )
1850 pPage = m_aPageList[nPos];
1851 else
1853 pPage = VclPtr<XFormsPage>::Create(m_pTabCtrl, this, DGTInstance);
1854 m_aPageList.push_back( pPage );
1858 return pPage;
1861 void DataNavigatorWindow::LoadModels()
1863 if ( !m_xFrameModel.is() )
1865 // get model of active frame
1866 Reference< XController > xCtrl = m_xFrame->getController();
1867 if ( xCtrl.is() )
1871 m_xFrameModel = xCtrl->getModel();
1873 catch ( Exception& )
1875 SAL_WARN( "svx.form", "DataNavigatorWindow::LoadModels(): exception caught" );
1880 if ( m_xFrameModel.is() )
1884 Reference< css::xforms::XFormsSupplier > xFormsSupp( m_xFrameModel, UNO_QUERY );
1885 if ( xFormsSupp.is() )
1887 Reference< XNameContainer > xContainer = xFormsSupp->getXForms();
1888 if ( xContainer.is() )
1890 m_xDataContainer = xContainer;
1891 Sequence< OUString > aNameList = m_xDataContainer->getElementNames();
1892 sal_Int32 i, nCount = aNameList.getLength();
1893 OUString* pNames = aNameList.getArray();
1894 for ( i = 0; i < nCount; ++i )
1896 Any aAny = m_xDataContainer->getByName( pNames[i] );
1897 Reference< css::xforms::XModel > xFormsModel;
1898 if ( aAny >>= xFormsModel )
1899 m_pModelsBox->InsertEntry( xFormsModel->getID() );
1904 catch( Exception& )
1906 SAL_WARN( "svx.form", "DataNavigatorWindow::LoadModels(): exception caught" );
1910 if ( m_pModelsBox->GetEntryCount() > 0 )
1912 m_pModelsBox->SelectEntryPos(0);
1913 ModelSelectHdl(m_pModelsBox);
1917 void DataNavigatorWindow::SetPageModel()
1919 OUString sModel( m_pModelsBox->GetSelectEntry() );
1922 Any aAny = m_xDataContainer->getByName( sModel );
1923 Reference< css::xforms::XModel > xFormsModel;
1924 if ( aAny >>= xFormsModel )
1926 sal_uInt16 nPagePos = TAB_PAGE_NOTFOUND;
1927 sal_uInt16 nId = 0;
1928 XFormsPage* pPage = GetCurrentPage( nId );
1929 DBG_ASSERT( pPage, "DataNavigatorWindow::SetPageModel(): no page" );
1930 if (IsAdditionalPage(nId) || m_pTabCtrl->GetPageName(nId) == "instance")
1931 // instance page
1932 nPagePos = m_pTabCtrl->GetPagePos( nId );
1933 m_bIsNotifyDisabled = true;
1934 OUString sText = pPage->SetModel( xFormsModel, nPagePos );
1935 m_bIsNotifyDisabled = false;
1936 if ( !sText.isEmpty() )
1937 m_pTabCtrl->SetPageText( nId, sText );
1940 catch (const NoSuchElementException& )
1942 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" );
1944 catch( Exception& )
1946 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): unexpected exception" );
1950 void DataNavigatorWindow::InitPages()
1952 OUString sModel( m_pModelsBox->GetSelectEntry() );
1955 Any aAny = m_xDataContainer->getByName( sModel );
1956 Reference< css::xforms::XModel > xModel;
1957 if ( aAny >>= xModel )
1959 Reference< XEnumerationAccess > xNumAccess( xModel->getInstances(), UNO_QUERY );
1960 if ( xNumAccess.is() )
1962 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
1963 if ( xNum.is() && xNum->hasMoreElements() )
1965 sal_Int32 nAlreadyLoadedCount = m_aPageList.size();
1966 if ( !HasFirstInstancePage() && nAlreadyLoadedCount > 0 )
1967 nAlreadyLoadedCount--;
1968 sal_Int32 nIdx = 0;
1969 while ( xNum->hasMoreElements() )
1971 if ( nIdx > nAlreadyLoadedCount )
1973 Sequence< PropertyValue > xPropSeq;
1974 if ( xNum->nextElement() >>= xPropSeq )
1975 CreateInstancePage( xPropSeq );
1976 else
1978 SAL_WARN( "svx.form", "DataNavigator::InitPages(): invalid instance" );
1981 else
1982 xNum->nextElement();
1983 nIdx++;
1989 catch ( NoSuchElementException& )
1991 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" );
1993 catch( Exception& )
1995 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): unexpected exception" );
1999 void DataNavigatorWindow::ClearAllPageModels( bool bClearPages )
2001 if ( m_pInstPage )
2002 m_pInstPage->ClearModel();
2003 if ( m_pSubmissionPage )
2004 m_pSubmissionPage->ClearModel();
2005 if ( m_pBindingPage )
2006 m_pBindingPage->ClearModel();
2008 sal_Int32 i, nCount = m_aPageList.size();
2009 for ( i = 0; i < nCount; ++i )
2011 VclPtr<XFormsPage> pPage = m_aPageList[i];
2012 pPage->ClearModel();
2013 if ( bClearPages )
2014 pPage.disposeAndClear();
2017 if ( bClearPages )
2019 m_aPageList.clear();
2020 while ( m_pTabCtrl->GetPageCount() > MIN_PAGE_COUNT )
2021 m_pTabCtrl->RemovePage( m_pTabCtrl->GetPageId( 1 ) );
2025 void DataNavigatorWindow::CreateInstancePage( const Sequence< PropertyValue >& _xPropSeq )
2027 OUString sInstName;
2028 OUString sID( PN_INSTANCE_ID );
2029 const PropertyValue* pProps = _xPropSeq.getConstArray();
2030 const PropertyValue* pPropsEnd = pProps + _xPropSeq.getLength();
2031 for ( ; pProps != pPropsEnd; ++pProps )
2033 if ( sID == pProps->Name )
2035 pProps->Value >>= sInstName;
2036 break;
2040 sal_uInt16 nPageId = GetNewPageId();
2041 if ( sInstName.isEmpty() )
2043 SAL_WARN( "svx.form", "DataNavigatorWindow::CreateInstancePage(): instance without name" );
2044 OUString sTemp("untitled");
2045 sTemp += OUString::number( nPageId );
2046 sInstName = sTemp;
2048 m_pTabCtrl->InsertPage( nPageId, sInstName, m_pTabCtrl->GetPageCount() - 2 );
2051 bool DataNavigatorWindow::HasFirstInstancePage() const
2053 return (m_pTabCtrl->GetPageName(m_pTabCtrl->GetPageId(0)) == "instance");
2056 sal_uInt16 DataNavigatorWindow::GetNewPageId() const
2058 sal_uInt16 i, nMax = 0, nCount = m_pTabCtrl->GetPageCount();
2059 for ( i = 0; i < nCount; ++i )
2061 if ( nMax < m_pTabCtrl->GetPageId(i) )
2062 nMax = m_pTabCtrl->GetPageId(i);
2064 return ( nMax + 1 );
2067 void DataNavigatorWindow::Resize()
2069 vcl::Window *pChild = GetWindow(GetWindowType::FirstChild);
2070 if (!pChild)
2071 return;
2072 VclContainer::setLayoutAllocation(*pChild, Point(0,0), GetSizePixel());
2075 Size DataNavigatorWindow::GetOptimalSize() const
2077 const vcl::Window *pChild = GetWindow(GetWindowType::FirstChild);
2078 if (!pChild)
2079 return Window::GetOptimalSize();
2080 return VclContainer::getLayoutRequisition(*pChild);
2083 void DataNavigatorWindow::SetDocModified()
2085 SfxObjectShell* pCurrentDoc = SfxObjectShell::Current();
2086 DBG_ASSERT( pCurrentDoc, "DataNavigatorWindow::SetDocModified(): no objectshell" );
2087 if ( !pCurrentDoc->IsModified() && pCurrentDoc->IsEnableSetModified() )
2088 pCurrentDoc->SetModified();
2091 void DataNavigatorWindow::NotifyChanges( bool _bLoadAll )
2093 if ( !m_bIsNotifyDisabled )
2095 if ( _bLoadAll )
2097 // reset all members
2098 RemoveBroadcaster();
2099 m_xDataContainer.clear();
2100 m_xFrameModel.clear();
2101 m_pModelsBox->Clear();
2102 m_nLastSelectedPos = LISTBOX_ENTRY_NOTFOUND;
2103 // for a reload
2104 LoadModels();
2106 else
2107 m_aUpdateTimer.Start();
2112 void DataNavigatorWindow::AddContainerBroadcaster( const XContainer_ref& xContainer )
2114 Reference< XContainerListener > xListener(
2115 static_cast< XContainerListener* >( m_xDataListener.get() ), UNO_QUERY );
2116 xContainer->addContainerListener( xListener );
2117 m_aContainerList.push_back( xContainer );
2121 void DataNavigatorWindow::AddEventBroadcaster( const XEventTarget_ref& xTarget )
2123 Reference< XEventListener > xListener(
2124 static_cast< XEventListener* >( m_xDataListener.get() ), UNO_QUERY );
2125 xTarget->addEventListener( EVENTTYPE_CHARDATA, xListener, true );
2126 xTarget->addEventListener( EVENTTYPE_CHARDATA, xListener, false );
2127 xTarget->addEventListener( EVENTTYPE_ATTR, xListener, true );
2128 xTarget->addEventListener( EVENTTYPE_ATTR, xListener, false );
2129 m_aEventTargetList.push_back( xTarget );
2133 void DataNavigatorWindow::RemoveBroadcaster()
2135 Reference< XContainerListener > xContainerListener(
2136 static_cast< XContainerListener* >( m_xDataListener.get() ), UNO_QUERY );
2137 sal_Int32 i, nCount = m_aContainerList.size();
2138 for ( i = 0; i < nCount; ++i )
2139 m_aContainerList[i]->removeContainerListener( xContainerListener );
2140 Reference< XEventListener > xEventListener(
2141 static_cast< XEventListener* >( m_xDataListener.get() ), UNO_QUERY );
2142 nCount = m_aEventTargetList.size();
2143 for ( i = 0; i < nCount; ++i )
2145 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_CHARDATA, xEventListener, true );
2146 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_CHARDATA, xEventListener, false );
2147 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_ATTR, xEventListener, true );
2148 m_aEventTargetList[i]->removeEventListener( EVENTTYPE_ATTR, xEventListener, false );
2152 DataNavigator::DataNavigator( SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* _pParent ) :
2154 SfxDockingWindow( _pBindings, _pMgr, _pParent,
2155 WinBits(WB_STDMODELESS|WB_SIZEABLE|WB_ROLLABLE|WB_3DLOOK|WB_DOCKABLE) ),
2156 SfxControllerItem( SID_FM_DATANAVIGATOR_CONTROL, *_pBindings ),
2158 m_aDataWin( VclPtr<DataNavigatorWindow>::Create(this, _pBindings) )
2162 SetText( SVX_RES( RID_STR_DATANAVIGATOR ) );
2164 Size aSize = m_aDataWin->GetOutputSizePixel();
2165 Size aLogSize = PixelToLogic( aSize, MAP_APPFONT );
2166 SfxDockingWindow::SetFloatingSize( aLogSize );
2168 m_aDataWin->Show();
2172 DataNavigator::~DataNavigator()
2174 disposeOnce();
2177 void DataNavigator::dispose()
2179 m_aDataWin.disposeAndClear();
2180 ::SfxControllerItem::dispose();
2181 SfxDockingWindow::dispose();
2184 void DataNavigator::StateChanged( sal_uInt16 , SfxItemState , const SfxPoolItem* )
2189 void DataNavigator::GetFocus()
2191 SfxDockingWindow::GetFocus();
2195 bool DataNavigator::Close()
2197 return SfxDockingWindow::Close();
2201 Size DataNavigator::CalcDockingSize( SfxChildAlignment eAlign )
2203 if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) )
2204 return Size();
2206 return SfxDockingWindow::CalcDockingSize( eAlign );
2210 SfxChildAlignment DataNavigator::CheckAlignment( SfxChildAlignment eActAlign, SfxChildAlignment eAlign )
2212 switch ( eAlign )
2214 case SfxChildAlignment::LEFT:
2215 case SfxChildAlignment::RIGHT:
2216 case SfxChildAlignment::NOALIGNMENT:
2217 return eAlign;
2218 default:
2219 break;
2221 return eActAlign;
2225 void DataNavigator::Resize()
2227 SfxDockingWindow::Resize();
2229 Size aLogOutputSize = PixelToLogic( GetOutputSizePixel(), MAP_APPFONT );
2230 Size aLogExplSize = aLogOutputSize;
2231 aLogExplSize.Width() -= 2;
2232 aLogExplSize.Height() -= 2;
2234 Point aExplPos = LogicToPixel( Point(1,1), MAP_APPFONT );
2235 Size aExplSize = LogicToPixel( aLogExplSize, MAP_APPFONT );
2237 m_aDataWin->SetPosSizePixel( aExplPos, aExplSize );
2242 // class NavigatorFrameManager
2246 SFX_IMPL_DOCKINGWINDOW( DataNavigatorManager, SID_FM_SHOW_DATANAVIGATOR )
2249 DataNavigatorManager::DataNavigatorManager(
2250 vcl::Window* _pParent, sal_uInt16 _nId, SfxBindings* _pBindings, SfxChildWinInfo* _pInfo ) :
2252 SfxChildWindow( _pParent, _nId )
2255 pWindow = VclPtr<DataNavigator>::Create( _pBindings, this, _pParent );
2256 eChildAlignment = SfxChildAlignment::RIGHT;
2257 pWindow->SetSizePixel( Size( 250, 400 ) );
2258 static_cast<SfxDockingWindow*>(pWindow.get())->Initialize( _pInfo );
2261 AddDataItemDialog::AddDataItemDialog(vcl::Window* pParent, ItemNode* _pNode,
2262 const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper)
2263 : ModalDialog(pParent, "AddDataItemDialog" , "svx/ui/adddataitemdialog.ui")
2264 , m_xUIHelper(_rUIHelper)
2265 , m_pItemNode(_pNode)
2266 , m_eItemType(DITNone)
2267 , m_sFL_Element(SVX_RESSTR(RID_STR_ELEMENT))
2268 , m_sFL_Attribute(SVX_RESSTR(RID_STR_ATTRIBUTE))
2269 , m_sFL_Binding(SVX_RESSTR(RID_STR_BINDING))
2270 , m_sFT_BindingExp(SVX_RESSTR(RID_STR_BINDING_EXPR))
2272 get(m_pItemFrame, "itemframe");
2273 get(m_pNameFT, "nameft");
2274 get(m_pNameED, "name");
2275 get(m_pDefaultFT, "valueft");
2276 get(m_pDefaultED, "value");
2277 get(m_pDefaultBtn, "browse");
2278 get(m_pSettingsFrame, "settingsframe");
2279 get(m_pDataTypeFT, "datatypeft");
2280 get(m_pDataTypeLB, "datatype");
2281 get(m_pRequiredCB, "required");
2282 get(m_pRequiredBtn, "requiredcond");
2283 get(m_pRelevantCB, "relevant");
2284 get(m_pRelevantBtn, "relevantcond");
2285 get(m_pConstraintCB, "constraint");
2286 get(m_pConstraintBtn, "constraintcond");
2287 get(m_pReadonlyCB, "readonly");
2288 get(m_pReadonlyBtn, "readonlycond");
2289 get(m_pCalculateCB, "calculate");
2290 get(m_pCalculateBtn, "calculatecond");
2291 get(m_pOKBtn, "ok");
2292 m_pDataTypeLB->SetDropDownLineCount( 10 );
2294 InitDialog();
2295 InitFromNode();
2296 InitDataTypeBox();
2297 CheckHdl( NULL );
2301 AddDataItemDialog::~AddDataItemDialog()
2303 disposeOnce();
2306 void AddDataItemDialog::dispose()
2308 if ( m_xTempBinding.is() )
2310 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2311 if ( xModel.is() )
2315 Reference < XSet > xBindings = xModel->getBindings();
2316 if ( xBindings.is() )
2317 xBindings->remove( makeAny( m_xTempBinding ) );
2319 catch (const Exception&)
2321 SAL_WARN( "svx.form", "AddDataItemDialog::Dtor(): exception caught" );
2325 if( m_xUIHelper.is() && m_xBinding.is() )
2327 // remove binding, if it does not convey 'useful' information
2328 m_xUIHelper->removeBindingIfUseless( m_xBinding );
2330 m_pItemFrame.clear();
2331 m_pNameFT.clear();
2332 m_pNameED.clear();
2333 m_pDefaultFT.clear();
2334 m_pDefaultED.clear();
2335 m_pDefaultBtn.clear();
2336 m_pSettingsFrame.clear();
2337 m_pDataTypeFT.clear();
2338 m_pDataTypeLB.clear();
2339 m_pRequiredCB.clear();
2340 m_pRequiredBtn.clear();
2341 m_pRelevantCB.clear();
2342 m_pRelevantBtn.clear();
2343 m_pConstraintCB.clear();
2344 m_pConstraintBtn.clear();
2345 m_pReadonlyCB.clear();
2346 m_pReadonlyBtn.clear();
2347 m_pCalculateCB.clear();
2348 m_pCalculateBtn.clear();
2349 m_pOKBtn.clear();
2350 ModalDialog::dispose();
2354 IMPL_LINK( AddDataItemDialog, CheckHdl, CheckBox *, pBox )
2356 // Condition buttons are only enable if their check box is checked
2357 m_pReadonlyBtn->Enable( m_pReadonlyCB->IsChecked() );
2358 m_pRequiredBtn->Enable( m_pRequiredCB->IsChecked() );
2359 m_pRelevantBtn->Enable( m_pRelevantCB->IsChecked() );
2360 m_pConstraintBtn->Enable( m_pConstraintCB->IsChecked() );
2361 m_pCalculateBtn->Enable( m_pCalculateCB->IsChecked() );
2363 if ( pBox && m_xTempBinding.is() )
2365 OUString sTemp, sPropName;
2366 if ( m_pRequiredCB == pBox )
2367 sPropName = PN_REQUIRED_EXPR;
2368 else if ( m_pRelevantCB == pBox )
2369 sPropName = PN_RELEVANT_EXPR;
2370 else if ( m_pConstraintCB == pBox )
2371 sPropName = PN_CONSTRAINT_EXPR;
2372 else if ( m_pReadonlyCB == pBox )
2373 sPropName = PN_READONLY_EXPR;
2374 else if ( m_pCalculateCB == pBox )
2375 sPropName = PN_CALCULATE_EXPR;
2376 bool bIsChecked = pBox->IsChecked();
2377 m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp;
2378 if ( bIsChecked && sTemp.isEmpty() )
2379 sTemp = TRUE_VALUE;
2380 else if ( !bIsChecked && !sTemp.isEmpty() )
2381 sTemp.clear();
2382 m_xTempBinding->setPropertyValue( sPropName, makeAny( sTemp ) );
2385 return 0;
2389 IMPL_LINK( AddDataItemDialog, ConditionHdl, PushButton *, pBtn )
2391 OUString sTemp, sPropName;
2392 if ( m_pDefaultBtn == pBtn )
2393 sPropName = PN_BINDING_EXPR;
2394 else if ( m_pRequiredBtn == pBtn )
2395 sPropName = PN_REQUIRED_EXPR;
2396 else if ( m_pRelevantBtn == pBtn )
2397 sPropName = PN_RELEVANT_EXPR;
2398 else if ( m_pConstraintBtn == pBtn )
2399 sPropName = PN_CONSTRAINT_EXPR;
2400 else if (m_pReadonlyBtn == pBtn)
2401 sPropName = PN_READONLY_EXPR;
2402 else if (m_pCalculateBtn == pBtn)
2403 sPropName = PN_CALCULATE_EXPR;
2404 ScopedVclPtrInstance< AddConditionDialog > aDlg(this, sPropName, m_xTempBinding);
2405 bool bIsDefBtn = ( m_pDefaultBtn == pBtn );
2406 OUString sCondition;
2407 if ( bIsDefBtn )
2408 sCondition = m_pDefaultED->GetText();
2409 else
2411 m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp;
2412 if ( sTemp.isEmpty() )
2413 sTemp = TRUE_VALUE;
2414 sCondition = sTemp;
2416 aDlg->SetCondition( sCondition );
2418 if ( aDlg->Execute() == RET_OK )
2420 OUString sNewCondition = aDlg->GetCondition();
2421 if ( bIsDefBtn )
2422 m_pDefaultED->SetText( sNewCondition );
2423 else
2426 m_xTempBinding->setPropertyValue(
2427 sPropName, makeAny( OUString( sNewCondition ) ) );
2430 return 0;
2433 void copyPropSet( const Reference< XPropertySet >& xFrom, Reference< XPropertySet >& xTo )
2435 DBG_ASSERT( xFrom.is(), "copyPropSet(): no source" );
2436 DBG_ASSERT( xTo.is(), "copyPropSet(): no target" );
2440 // get property names & infos, and iterate over target properties
2441 Sequence< Property > aProperties = xTo->getPropertySetInfo()->getProperties();
2442 sal_Int32 nProperties = aProperties.getLength();
2443 const Property* pProperties = aProperties.getConstArray();
2444 Reference< XPropertySetInfo > xFromInfo = xFrom->getPropertySetInfo();
2445 for ( sal_Int32 i = 0; i < nProperties; ++i )
2447 const OUString& rName = pProperties[i].Name;
2449 // if both set have the property, copy the value
2450 // (catch and ignore exceptions, if any)
2451 if ( xFromInfo->hasPropertyByName( rName ) )
2453 // don't set readonly properties
2454 Property aProperty = xFromInfo->getPropertyByName( rName );
2455 if ( ( aProperty.Attributes & PropertyAttribute::READONLY ) == 0 )
2456 xTo->setPropertyValue(rName, xFrom->getPropertyValue( rName ));
2458 // else: no property? then ignore.
2461 catch ( Exception& )
2463 SAL_WARN( "svx.form", "copyPropSet(): exception caught" );
2468 IMPL_LINK_NOARG(AddDataItemDialog, OKHdl)
2470 bool bIsHandleBinding = ( DITBinding == m_eItemType );
2471 bool bIsHandleText = ( DITText == m_eItemType );
2472 OUString sNewName( m_pNameED->GetText() );
2474 if ( ( !bIsHandleBinding && !bIsHandleText && !m_xUIHelper->isValidXMLName( sNewName ) ) ||
2475 ( bIsHandleBinding && sNewName.isEmpty() ) )
2477 // Error and don't close the dialog
2478 ScopedVclPtrInstance< MessageDialog > aErrBox( this, SVX_RES( RID_STR_INVALID_XMLNAME ) );
2479 aErrBox->set_primary_text(aErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sNewName));
2480 aErrBox->Execute();
2481 return 0;
2484 OUString sDataType( m_pDataTypeLB->GetSelectEntry() );
2485 m_xTempBinding->setPropertyValue( PN_BINDING_TYPE, makeAny( sDataType ) );
2487 if ( bIsHandleBinding )
2489 // copy properties from temp binding to original binding
2490 copyPropSet( m_xTempBinding, m_pItemNode->m_xPropSet );
2493 OUString sValue = m_pNameED->GetText();
2494 m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_ID, makeAny( sValue ) );
2495 sValue = m_pDefaultED->GetText();
2496 m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_EXPR, makeAny( sValue ) );
2498 catch ( Exception& )
2500 SAL_WARN( "svx.form", "AddDataDialog::OKHdl(): exception caught" );
2503 else
2505 // copy properties from temp binding to original binding
2506 copyPropSet( m_xTempBinding, m_xBinding );
2509 if ( bIsHandleText )
2510 m_xUIHelper->setNodeValue( m_pItemNode->m_xNode, m_pDefaultED->GetText() );
2511 else
2513 Reference< css::xml::dom::XNode > xNewNode =
2514 m_xUIHelper->renameNode( m_pItemNode->m_xNode, m_pNameED->GetText() );
2515 m_xUIHelper->setNodeValue( xNewNode, m_pDefaultED->GetText() );
2516 m_pItemNode->m_xNode = xNewNode;
2519 catch ( Exception& )
2521 SAL_WARN( "svx.form", "AddDataDialog::OKHdl(): exception caught" );
2524 // then close the dialog
2525 EndDialog( RET_OK );
2526 return 0;
2530 void AddDataItemDialog::InitDialog()
2532 // set handler
2533 Link<> aLink = LINK( this, AddDataItemDialog, CheckHdl );
2534 m_pRequiredCB->SetClickHdl( aLink );
2535 m_pRelevantCB->SetClickHdl( aLink );
2536 m_pConstraintCB->SetClickHdl( aLink );
2537 m_pReadonlyCB->SetClickHdl( aLink );
2538 m_pCalculateCB->SetClickHdl( aLink );
2540 aLink = LINK( this, AddDataItemDialog, ConditionHdl );
2541 m_pDefaultBtn->SetClickHdl( aLink );
2542 m_pRequiredBtn->SetClickHdl( aLink );
2543 m_pRelevantBtn->SetClickHdl( aLink );
2544 m_pConstraintBtn->SetClickHdl( aLink );
2545 m_pReadonlyBtn->SetClickHdl( aLink );
2546 m_pCalculateBtn->SetClickHdl( aLink );
2548 m_pOKBtn->SetClickHdl( LINK( this, AddDataItemDialog, OKHdl ) );
2552 void AddDataItemDialog::InitFromNode()
2554 if ( m_pItemNode )
2556 if ( m_pItemNode->m_xNode.is() )
2560 // detect type of the node
2561 css::xml::dom::NodeType eChildType = m_pItemNode->m_xNode->getNodeType();
2562 switch ( eChildType )
2564 case css::xml::dom::NodeType_ATTRIBUTE_NODE:
2565 m_eItemType = DITAttribute;
2566 break;
2567 case css::xml::dom::NodeType_ELEMENT_NODE:
2568 m_eItemType = DITElement;
2569 break;
2570 case css::xml::dom::NodeType_TEXT_NODE:
2571 m_eItemType = DITText;
2572 break;
2573 default:
2574 OSL_FAIL( "AddDataItemDialog::InitFronNode: cannot handle this node type!" );
2575 break;
2578 /** Get binding of the node and clone it
2579 Then use this temporary binding in the dialog.
2580 When the user click OK the temporary binding will be copied
2581 into the original binding.
2584 Reference< css::xml::dom::XNode > xNode = m_pItemNode->m_xNode;
2585 m_xBinding = m_xUIHelper->getBindingForNode( xNode, sal_True );
2586 if ( m_xBinding.is() )
2588 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2589 if ( xModel.is() )
2591 m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_xBinding );
2592 Reference < XSet > xBindings = xModel->getBindings();
2593 if ( xBindings.is() )
2594 xBindings->insert( makeAny( m_xTempBinding ) );
2598 if ( m_eItemType != DITText )
2600 OUString sName( m_xUIHelper->getNodeName( m_pItemNode->m_xNode ) );
2601 m_pNameED->SetText( sName );
2603 m_pDefaultED->SetText( m_pItemNode->m_xNode->getNodeValue() );
2605 catch( Exception& )
2607 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2610 else if ( m_pItemNode->m_xPropSet.is() )
2612 m_eItemType = DITBinding;
2613 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2614 if ( xModel.is() )
2618 m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_pItemNode->m_xPropSet );
2619 Reference < XSet > xBindings = xModel->getBindings();
2620 if ( xBindings.is() )
2621 xBindings->insert( makeAny( m_xTempBinding ) );
2623 catch ( Exception& )
2625 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2628 OUString sTemp;
2631 Reference< XPropertySetInfo > xInfo = m_pItemNode->m_xPropSet->getPropertySetInfo();
2632 if ( xInfo->hasPropertyByName( PN_BINDING_ID ) )
2634 m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
2635 m_pNameED->SetText( sTemp );
2636 m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
2637 m_pDefaultED->SetText( sTemp );
2639 else if ( xInfo->hasPropertyByName( PN_SUBMISSION_BIND ) )
2641 m_pItemNode->m_xPropSet->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
2642 m_pNameED->SetText( sTemp );
2645 catch( Exception& )
2647 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2650 Size a3and1Sz = LogicToPixel( Size( 3, 1 ), MAP_APPFONT );
2651 Size aNewSz = m_pDefaultED->GetSizePixel();
2652 Point aNewPnt = m_pDefaultED->GetPosPixel();
2653 aNewPnt.Y() += a3and1Sz.Height();
2654 aNewSz.Width() -= ( m_pDefaultBtn->GetSizePixel().Width() + a3and1Sz.Width() );
2655 m_pDefaultED->SetPosSizePixel( aNewPnt, aNewSz );
2656 m_pDefaultBtn->Show();
2659 if ( m_xTempBinding.is() )
2661 OUString sTemp;
2664 if ( ( m_xTempBinding->getPropertyValue( PN_REQUIRED_EXPR ) >>= sTemp )
2665 && !sTemp.isEmpty() )
2666 m_pRequiredCB->Check( true );
2667 if ( ( m_xTempBinding->getPropertyValue( PN_RELEVANT_EXPR ) >>= sTemp )
2668 && !sTemp.isEmpty() )
2669 m_pRelevantCB->Check( true );
2670 if ( ( m_xTempBinding->getPropertyValue( PN_CONSTRAINT_EXPR ) >>= sTemp )
2671 && !sTemp.isEmpty() )
2672 m_pConstraintCB->Check( true );
2673 if ( ( m_xTempBinding->getPropertyValue( PN_READONLY_EXPR ) >>= sTemp )
2674 && !sTemp.isEmpty() )
2675 m_pReadonlyCB->Check( true );
2676 if ( ( m_xTempBinding->getPropertyValue( PN_CALCULATE_EXPR ) >>= sTemp )
2677 && !sTemp.isEmpty() )
2678 m_pCalculateCB->Check( true );
2680 catch (const Exception&)
2682 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2687 if ( DITText == m_eItemType )
2689 m_pSettingsFrame->Hide();
2690 m_pNameFT->Disable();
2691 m_pNameED->Disable();
2696 void AddDataItemDialog::InitDataTypeBox()
2698 if ( m_eItemType != DITText )
2700 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2701 if ( xModel.is() )
2705 Reference< css::xforms::XDataTypeRepository > xDataTypes =
2706 xModel->getDataTypeRepository();
2707 if ( xDataTypes.is() )
2709 Sequence< OUString > aNameList = xDataTypes->getElementNames();
2710 sal_Int32 i, nCount = aNameList.getLength();
2711 OUString* pNames = aNameList.getArray();
2712 for ( i = 0; i < nCount; ++i )
2713 m_pDataTypeLB->InsertEntry( pNames[i] );
2716 if ( m_xTempBinding.is() )
2718 OUString sTemp;
2719 if ( m_xTempBinding->getPropertyValue( PN_BINDING_TYPE ) >>= sTemp )
2721 sal_Int32 nPos = m_pDataTypeLB->GetEntryPos( sTemp );
2722 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
2723 nPos = m_pDataTypeLB->InsertEntry( sTemp );
2724 m_pDataTypeLB->SelectEntryPos( nPos );
2728 catch ( Exception& )
2730 SAL_WARN( "svx.form", "AddDataItemDialog::InitDataTypeBox(): exception caught" );
2736 void AddDataItemDialog::InitText( DataItemType _eType )
2738 OUString sText;
2740 switch ( _eType )
2742 case DITAttribute :
2744 sText = m_sFL_Attribute;
2745 break;
2748 case DITBinding :
2750 sText = m_sFL_Binding;
2751 m_pDefaultFT->SetText( m_sFT_BindingExp );
2752 break;
2755 default:
2757 sText = m_sFL_Element;
2761 m_pItemFrame->set_label(sText);
2764 AddConditionDialog::AddConditionDialog(vcl::Window* pParent,
2765 const OUString& _rPropertyName,
2766 const Reference< XPropertySet >& _rPropSet)
2767 : ModalDialog(pParent, "AddConditionDialog", "svx/ui/addconditiondialog.ui")
2768 , m_sPropertyName(_rPropertyName)
2769 , m_xBinding(_rPropSet)
2772 get(m_pConditionED, "condition");
2773 get(m_pResultWin, "result");
2774 get(m_pEditNamespacesBtn, "edit");
2775 get(m_pOKBtn, "ok");
2776 DBG_ASSERT( m_xBinding.is(), "AddConditionDialog::Ctor(): no Binding" );
2778 m_pConditionED->set_height_request(m_pConditionED->GetTextHeight() * 4);
2779 m_pConditionED->set_width_request(m_pConditionED->approximate_char_width() * 62);
2780 m_pResultWin->set_height_request(m_pResultWin->GetTextHeight() * 4);
2781 m_pResultWin->set_width_request(m_pResultWin->approximate_char_width() * 62);
2783 m_pConditionED->SetModifyHdl( LINK( this, AddConditionDialog, ModifyHdl ) );
2784 m_pEditNamespacesBtn->SetClickHdl( LINK( this, AddConditionDialog, EditHdl ) );
2785 m_pOKBtn->SetClickHdl( LINK( this, AddConditionDialog, OKHdl ) );
2786 m_aResultIdle.SetPriority( SchedulerPriority::LOWEST );
2787 m_aResultIdle.SetIdleHdl( LINK( this, AddConditionDialog, ResultHdl ) );
2789 if ( !m_sPropertyName.isEmpty() )
2793 OUString sTemp;
2794 if ( ( m_xBinding->getPropertyValue( m_sPropertyName ) >>= sTemp )
2795 && !sTemp.isEmpty() )
2797 m_pConditionED->SetText( sTemp );
2799 else
2801 //! m_xBinding->setPropertyValue( m_sPropertyName, makeAny( TRUE_VALUE ) );
2802 m_pConditionED->SetText( TRUE_VALUE );
2805 Reference< css::xforms::XModel > xModel;
2806 if ( ( m_xBinding->getPropertyValue( PN_BINDING_MODEL ) >>= xModel ) && xModel.is() )
2807 m_xUIHelper = Reference< css::xforms::XFormsUIHelper1 >( xModel, UNO_QUERY );
2809 catch (const Exception&)
2811 SAL_WARN( "svx.form", "AddConditionDialog::Ctor(): exception caught" );
2815 DBG_ASSERT( m_xUIHelper.is(), "AddConditionDialog::Ctor(): no UIHelper" );
2816 ResultHdl( &m_aResultIdle );
2819 AddConditionDialog::~AddConditionDialog()
2821 disposeOnce();
2824 void AddConditionDialog::dispose()
2826 m_pConditionED.clear();
2827 m_pResultWin.clear();
2828 m_pEditNamespacesBtn.clear();
2829 m_pOKBtn.clear();
2830 ModalDialog::dispose();
2833 IMPL_LINK_NOARG(AddConditionDialog, EditHdl)
2835 Reference< XNameContainer > xNameContnr;
2838 m_xBinding->getPropertyValue( PN_BINDING_NAMESPACES ) >>= xNameContnr;
2840 catch ( Exception& )
2842 SAL_WARN( "svx.form", "AddDataItemDialog::EditHdl(): exception caught" );
2844 ScopedVclPtrInstance< NamespaceItemDialog > aDlg( this, xNameContnr );
2845 aDlg->Execute();
2848 m_xBinding->setPropertyValue( PN_BINDING_NAMESPACES, makeAny( xNameContnr ) );
2850 catch ( Exception& )
2852 SAL_WARN( "svx.form", "AddDataItemDialog::EditHdl(): exception caught" );
2854 return 0;
2858 IMPL_LINK_NOARG(AddConditionDialog, OKHdl)
2860 /*!!!
2863 if ( m_xBinding.is() )
2864 m_xBinding->setPropertyValue( m_sPropertyName, makeAny( OUString( m_pConditionED->GetText() ) ) );
2866 catch( const Exception& )
2868 SAL_WARN( "svx.form", "AddConditionDialog, OKHdl: caught an exception!" );
2871 EndDialog( RET_OK );
2872 return 0;
2876 IMPL_LINK_NOARG(AddConditionDialog, ModifyHdl)
2878 m_aResultIdle.Start();
2879 return 0;
2883 IMPL_LINK_NOARG_TYPED(AddConditionDialog, ResultHdl, Idle *, void)
2885 OUString sCondition = comphelper::string::strip(m_pConditionED->GetText(), ' ');
2886 OUString sResult;
2887 if ( !sCondition.isEmpty() )
2891 sResult = m_xUIHelper->getResultForExpression( m_xBinding, ( m_sPropertyName == PN_BINDING_EXPR ), sCondition );
2893 catch ( Exception& )
2895 SAL_WARN( "svx.form", "AddConditionDialog::ResultHdl(): exception caught" );
2898 m_pResultWin->SetText( sResult );
2901 NamespaceItemDialog::NamespaceItemDialog(
2902 AddConditionDialog* _pCondDlg,
2903 Reference< XNameContainer >& _rContainer )
2904 : ModalDialog( _pCondDlg, "NamespaceDialog",
2905 "svx/ui/namespacedialog.ui" )
2906 , m_pConditionDlg(_pCondDlg)
2907 , m_rNamespaces(_rContainer)
2909 get(m_pAddNamespaceBtn, "add");
2910 get(m_pEditNamespaceBtn, "edit");
2911 get(m_pDeleteNamespaceBtn, "delete");
2912 get(m_pOKBtn, "ok");
2914 SvSimpleTableContainer* pNamespacesListContainer =
2915 get<SvSimpleTableContainer>("namespaces");
2916 Size aControlSize(175, 72);
2917 aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
2918 pNamespacesListContainer->set_width_request(aControlSize.Width());
2919 pNamespacesListContainer->set_height_request(aControlSize.Height());
2920 m_pNamespacesList = VclPtr<SvSimpleTable>::Create(*pNamespacesListContainer, 0);
2922 static long aStaticTabs[]= { 3, 0, 35, 200 };
2923 m_pNamespacesList->SvSimpleTable::SetTabs( aStaticTabs );
2924 OUString sHeader = get<FixedText>("prefix")->GetText();
2925 sHeader += "\t";
2926 sHeader += get<FixedText>("url")->GetText();
2927 m_pNamespacesList->InsertHeaderEntry(
2928 sHeader, HEADERBAR_APPEND, HeaderBarItemBits::LEFT /*| HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::FIXED*/ );
2930 m_pNamespacesList->SetSelectHdl( LINK( this, NamespaceItemDialog, SelectHdl ) );
2931 Link<> aLink = LINK( this, NamespaceItemDialog, ClickHdl );
2932 m_pAddNamespaceBtn->SetClickHdl( aLink );
2933 m_pEditNamespaceBtn->SetClickHdl( aLink );
2934 m_pDeleteNamespaceBtn->SetClickHdl( aLink );
2935 m_pOKBtn->SetClickHdl( LINK( this, NamespaceItemDialog, OKHdl ) );
2937 LoadNamespaces();
2938 SelectHdl( m_pNamespacesList );
2942 NamespaceItemDialog::~NamespaceItemDialog()
2944 disposeOnce();
2947 void NamespaceItemDialog::dispose()
2949 m_pNamespacesList.disposeAndClear();
2950 m_pAddNamespaceBtn.clear();
2951 m_pEditNamespaceBtn.clear();
2952 m_pDeleteNamespaceBtn.clear();
2953 m_pOKBtn.clear();
2954 m_pConditionDlg.clear();
2955 ModalDialog::dispose();
2959 IMPL_LINK( NamespaceItemDialog, SelectHdl, SvSimpleTable *, )
2961 bool bEnable = ( m_pNamespacesList->FirstSelected() != NULL );
2962 m_pEditNamespaceBtn->Enable( bEnable );
2963 m_pDeleteNamespaceBtn->Enable( bEnable );
2965 return 0;
2969 IMPL_LINK( NamespaceItemDialog, ClickHdl, PushButton *, pBtn )
2971 if ( m_pAddNamespaceBtn == pBtn )
2973 ScopedVclPtrInstance< ManageNamespaceDialog > aDlg(this, m_pConditionDlg, false);
2974 if ( aDlg->Execute() == RET_OK )
2976 OUString sEntry = aDlg->GetPrefix();
2977 sEntry += "\t";
2978 sEntry += aDlg->GetURL();
2979 m_pNamespacesList->InsertEntry( sEntry );
2982 else if ( m_pEditNamespaceBtn == pBtn )
2984 ScopedVclPtrInstance< ManageNamespaceDialog > aDlg( this, m_pConditionDlg, true );
2985 SvTreeListEntry* pEntry = m_pNamespacesList->FirstSelected();
2986 DBG_ASSERT( pEntry, "NamespaceItemDialog::ClickHdl(): no entry" );
2987 OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
2988 aDlg->SetNamespace(
2989 sPrefix,
2990 SvTabListBox::GetEntryText( pEntry, 1 ) );
2991 if ( aDlg->Execute() == RET_OK )
2993 // if a prefix was changed, mark the old prefix as 'removed'
2994 if( sPrefix != aDlg->GetPrefix() )
2995 m_aRemovedList.push_back( sPrefix );
2997 m_pNamespacesList->SetEntryText( aDlg->GetPrefix(), pEntry, 0 );
2998 m_pNamespacesList->SetEntryText( aDlg->GetURL(), pEntry, 1 );
3001 else if ( m_pDeleteNamespaceBtn == pBtn )
3003 SvTreeListEntry* pEntry = m_pNamespacesList->FirstSelected();
3004 DBG_ASSERT( pEntry, "NamespaceItemDialog::ClickHdl(): no entry" );
3005 OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
3006 m_aRemovedList.push_back( sPrefix );
3007 m_pNamespacesList->GetModel()->Remove( pEntry );
3009 else
3011 SAL_WARN( "svx.form", "NamespaceItemDialog::ClickHdl(): invalid button" );
3014 SelectHdl( m_pNamespacesList );
3015 return 0;
3019 IMPL_LINK_NOARG(NamespaceItemDialog, OKHdl)
3023 // update namespace container
3024 sal_Int32 i, nRemovedCount = m_aRemovedList.size();
3025 for( i = 0; i < nRemovedCount; ++i )
3026 m_rNamespaces->removeByName( m_aRemovedList[i] );
3028 sal_Int32 nEntryCount = m_pNamespacesList->GetEntryCount();
3029 for( i = 0; i < nEntryCount; ++i )
3031 SvTreeListEntry* pEntry = m_pNamespacesList->GetEntry(i);
3032 OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
3033 OUString sURL( SvTabListBox::GetEntryText( pEntry, 1 ) );
3035 if ( m_rNamespaces->hasByName( sPrefix ) )
3036 m_rNamespaces->replaceByName( sPrefix, makeAny( sURL ) );
3037 else
3038 m_rNamespaces->insertByName( sPrefix, makeAny( sURL ) );
3041 catch ( Exception& )
3043 SAL_WARN( "svx.form", "NamespaceItemDialog::OKHdl(): exception caught" );
3045 // and close the dialog
3046 EndDialog( RET_OK );
3047 return 0;
3051 void NamespaceItemDialog::LoadNamespaces()
3055 Sequence< OUString > aAllNames = m_rNamespaces->getElementNames();
3056 const OUString* pAllNames = aAllNames.getConstArray();
3057 const OUString* pAllNamesEnd = pAllNames + aAllNames.getLength();
3058 for ( ; pAllNames != pAllNamesEnd; ++pAllNames )
3060 OUString sURL;
3061 OUString sPrefix = *pAllNames;
3062 if ( m_rNamespaces->hasByName( sPrefix ) )
3064 Any aAny = m_rNamespaces->getByName( sPrefix );
3065 if ( aAny >>= sURL )
3067 OUString sEntry( sPrefix );
3068 sEntry += "\t";
3069 sEntry += sURL;
3071 m_pNamespacesList->InsertEntry( sEntry );
3076 catch ( Exception& )
3078 SAL_WARN( "svx.form", "NamespaceItemDialog::LoadNamespaces(): exception caught" );
3082 ManageNamespaceDialog::ManageNamespaceDialog(vcl::Window* pParent, AddConditionDialog* _pCondDlg, bool bIsEdit)
3083 : ModalDialog(pParent, "AddNamespaceDialog", "svx/ui/addnamespacedialog.ui")
3084 , m_pConditionDlg ( _pCondDlg )
3086 get(m_pOKBtn, "ok");
3087 get(m_pPrefixED, "prefix");
3088 get(m_pUrlED, "url");
3090 if (bIsEdit)
3091 SetText(get<FixedText>("alttitle")->GetText());
3093 m_pOKBtn->SetClickHdl( LINK( this, ManageNamespaceDialog, OKHdl ) );
3096 ManageNamespaceDialog::~ManageNamespaceDialog()
3098 disposeOnce();
3101 void ManageNamespaceDialog::dispose()
3103 m_pOKBtn.clear();
3104 m_pPrefixED.clear();
3105 m_pUrlED.clear();
3106 m_pConditionDlg.clear();
3107 ModalDialog::dispose();
3110 IMPL_LINK_NOARG(ManageNamespaceDialog, OKHdl)
3112 OUString sPrefix = m_pPrefixED->GetText();
3116 if ( !m_pConditionDlg->GetUIHelper()->isValidPrefixName( sPrefix ) )
3118 ScopedVclPtrInstance< MessageDialog > aErrBox(this, SVX_RES( RID_STR_INVALID_XMLPREFIX ) );
3119 aErrBox->set_primary_text(aErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sPrefix));
3120 aErrBox->Execute();
3121 return 0;
3124 catch ( Exception& )
3126 SAL_WARN( "svx.form", "ManageNamespacesDialog::OKHdl(): exception caught" );
3129 // no error so close the dialog
3130 EndDialog( RET_OK );
3131 return 0;
3134 AddSubmissionDialog::AddSubmissionDialog(
3135 vcl::Window* pParent, ItemNode* _pNode,
3136 const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper)
3137 : ModalDialog(pParent, "AddSubmissionDialog",
3138 "svx/ui/addsubmissiondialog.ui")
3139 , m_pItemNode(_pNode)
3140 , m_xUIHelper(_rUIHelper)
3142 get(m_pNameED, "name");
3143 get(m_pActionED, "action");
3144 get(m_pMethodLB, "method");
3145 get(m_pRefED, "expression");
3146 get(m_pRefBtn, "browse");
3147 get(m_pBindLB, "binding");
3148 get(m_pReplaceLB, "replace");
3149 get(m_pOKBtn, "ok");
3150 FillAllBoxes();
3152 m_pRefBtn->SetClickHdl( LINK( this, AddSubmissionDialog, RefHdl ) );
3153 m_pOKBtn->SetClickHdl( LINK( this, AddSubmissionDialog, OKHdl ) );
3157 AddSubmissionDialog::~AddSubmissionDialog()
3159 disposeOnce();
3162 void AddSubmissionDialog::dispose()
3164 // #i38991# if we have added a binding, we need to remove it as well.
3165 if( m_xCreatedBinding.is() && m_xUIHelper.is() )
3166 m_xUIHelper->removeBindingIfUseless( m_xCreatedBinding );
3167 m_pNameED.clear();
3168 m_pActionED.clear();
3169 m_pMethodLB.clear();
3170 m_pRefED.clear();
3171 m_pRefBtn.clear();
3172 m_pBindLB.clear();
3173 m_pReplaceLB.clear();
3174 m_pOKBtn.clear();
3175 ModalDialog::dispose();
3179 IMPL_LINK_NOARG(AddSubmissionDialog, RefHdl)
3181 ScopedVclPtrInstance< AddConditionDialog > aDlg(this, PN_BINDING_EXPR, m_xTempBinding );
3182 aDlg->SetCondition( m_pRefED->GetText() );
3183 if ( aDlg->Execute() == RET_OK )
3184 m_pRefED->SetText( aDlg->GetCondition() );
3186 return 0;
3190 IMPL_LINK_NOARG(AddSubmissionDialog, OKHdl)
3192 OUString sName(m_pNameED->GetText());
3193 if(sName.isEmpty()) {
3195 ScopedVclPtrInstance< MessageDialog > aErrorBox(this,SVX_RES(RID_STR_EMPTY_SUBMISSIONNAME));
3196 aErrorBox->set_primary_text( Application::GetDisplayName() );
3197 aErrorBox->Execute();
3198 return 0;
3201 if ( !m_xSubmission.is() )
3203 DBG_ASSERT( !m_xNewSubmission.is(),
3204 "AddSubmissionDialog::OKHdl(): new submission already exists" );
3206 // add a new submission
3207 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
3208 if ( xModel.is() )
3212 m_xNewSubmission = xModel->createSubmission();
3213 m_xSubmission = Reference< XPropertySet >( m_xNewSubmission, UNO_QUERY );
3215 catch ( Exception& )
3217 SAL_WARN( "svx.form", "AddSubmissionDialog::OKHdl(): exception caught" );
3222 if ( m_xSubmission.is() )
3224 OUString sTemp = m_pNameED->GetText();
3227 m_xSubmission->setPropertyValue( PN_SUBMISSION_ID, makeAny( sTemp ) );
3228 sTemp = m_pActionED->GetText();
3229 m_xSubmission->setPropertyValue( PN_SUBMISSION_ACTION, makeAny( sTemp ) );
3230 sTemp = m_aMethodString.toAPI( m_pMethodLB->GetSelectEntry() );
3231 m_xSubmission->setPropertyValue( PN_SUBMISSION_METHOD, makeAny( sTemp ) );
3232 sTemp = m_pRefED->GetText();
3233 m_xSubmission->setPropertyValue( PN_SUBMISSION_REF, makeAny( sTemp ) );
3234 OUString sEntry = m_pBindLB->GetSelectEntry();
3235 sal_Int32 nColonIdx = sEntry.indexOf(':');
3236 if (nColonIdx != -1)
3237 sEntry = sEntry.copy(0, nColonIdx);
3238 sTemp = sEntry;
3239 m_xSubmission->setPropertyValue( PN_SUBMISSION_BIND, makeAny( sTemp ) );
3240 sTemp = m_aReplaceString.toAPI( m_pReplaceLB->GetSelectEntry() );
3241 m_xSubmission->setPropertyValue( PN_SUBMISSION_REPLACE, makeAny( sTemp ) );
3243 catch ( Exception& )
3245 SAL_WARN( "svx.form", "AddSubmissionDialog::OKHdl(): exception caught" );
3249 EndDialog( RET_OK );
3250 return 0;
3254 void AddSubmissionDialog::FillAllBoxes()
3256 // method box
3257 m_pMethodLB->InsertEntry( SVX_RESSTR( RID_STR_METHOD_POST ) );
3258 m_pMethodLB->InsertEntry( SVX_RESSTR( RID_STR_METHOD_PUT ) );
3259 m_pMethodLB->InsertEntry( SVX_RESSTR( RID_STR_METHOD_GET ) );
3260 m_pMethodLB->SelectEntryPos(0);
3262 // binding box
3263 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
3264 if ( xModel.is() )
3268 Reference< XEnumerationAccess > xNumAccess( xModel->getBindings(), UNO_QUERY );
3269 if ( xNumAccess.is() )
3271 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
3272 if ( xNum.is() && xNum->hasMoreElements() )
3274 OUString sDelim( ": " );
3275 while ( xNum->hasMoreElements() )
3277 Reference< XPropertySet > xPropSet;
3278 Any aAny = xNum->nextElement();
3279 if ( aAny >>= xPropSet )
3281 OUString sEntry;
3282 OUString sTemp;
3283 xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
3284 sEntry += sTemp;
3285 sEntry += sDelim;
3286 xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
3287 sEntry += sTemp;
3288 m_pBindLB->InsertEntry( sEntry );
3290 if ( !m_xTempBinding.is() )
3291 m_xTempBinding = xPropSet;
3297 catch ( Exception& )
3299 SAL_WARN( "svx.form", "AddSubmissionDialog::FillAllBoxes(): exception caught" );
3303 // #i36342# we need a temporary binding; create one if no existing binding
3304 // is found
3305 if( !m_xTempBinding.is() )
3307 m_xCreatedBinding = m_xUIHelper->getBindingForNode(
3308 Reference<css::xml::dom::XNode>(
3309 xModel->getDefaultInstance()->getDocumentElement(),
3310 UNO_QUERY_THROW ),
3311 sal_True );
3312 m_xTempBinding = m_xCreatedBinding;
3315 // replace box
3316 m_pReplaceLB->InsertEntry( SVX_RESSTR( RID_STR_REPLACE_NONE ) );
3317 m_pReplaceLB->InsertEntry( SVX_RESSTR( RID_STR_REPLACE_INST ) );
3318 m_pReplaceLB->InsertEntry( SVX_RESSTR( RID_STR_REPLACE_DOC ) );
3321 // init the controls with the values of the submission
3322 if ( m_pItemNode && m_pItemNode->m_xPropSet.is() )
3324 m_xSubmission = m_pItemNode->m_xPropSet;
3325 OUString sTemp;
3328 m_xSubmission->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
3329 m_pNameED->SetText( sTemp );
3330 m_xSubmission->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp;
3331 m_pActionED->SetText( sTemp );
3332 m_xSubmission->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp;
3333 m_pRefED->SetText( sTemp );
3335 m_xSubmission->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp;
3336 sTemp = m_aMethodString.toUI( sTemp );
3337 sal_Int32 nPos = m_pMethodLB->GetEntryPos( sTemp );
3338 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
3339 nPos = m_pMethodLB->InsertEntry( sTemp );
3340 m_pMethodLB->SelectEntryPos( nPos );
3342 m_xSubmission->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp;
3343 nPos = m_pBindLB->GetEntryPos( sTemp );
3344 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
3345 nPos = m_pBindLB->InsertEntry( sTemp );
3346 m_pBindLB->SelectEntryPos( nPos );
3348 m_xSubmission->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp;
3349 sTemp = m_aReplaceString.toUI( sTemp );
3350 if ( sTemp.isEmpty() )
3351 sTemp = m_pReplaceLB->GetEntry(0); // first entry == "none"
3352 nPos = m_pReplaceLB->GetEntryPos( sTemp );
3353 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
3354 nPos = m_pReplaceLB->InsertEntry( sTemp );
3355 m_pReplaceLB->SelectEntryPos( nPos );
3357 catch ( Exception& )
3359 SAL_WARN( "svx.form", "AddSubmissionDialog::FillAllBoxes(): exception caught" );
3363 m_pRefBtn->Enable( m_xTempBinding.is() );
3366 AddModelDialog::AddModelDialog(vcl::Window* pParent, bool bIsEdit)
3367 : ModalDialog(pParent, "AddModelDialog", "svx/ui/addmodeldialog.ui")
3369 get(m_pNameED, "name");
3370 get(m_pModifyCB, "modify");
3372 if (bIsEdit)
3373 SetText(get<FixedText>("alttitle")->GetText());
3376 AddModelDialog::~AddModelDialog()
3378 disposeOnce();
3381 void AddModelDialog::dispose()
3383 m_pNameED.clear();
3384 m_pModifyCB.clear();
3385 ModalDialog::dispose();
3388 AddInstanceDialog::AddInstanceDialog(vcl::Window* pParent, bool _bEdit)
3389 : ModalDialog(pParent, "AddInstanceDialog" , "svx/ui/addinstancedialog.ui")
3391 get(m_pNameED, "name");
3392 get(m_pURLFT, "urlft");
3393 get(m_pURLED, "url");
3394 get(m_pFilePickerBtn, "browse");
3395 get(m_pLinkInstanceCB, "link");
3397 if ( _bEdit )
3398 SetText(get<FixedText>("alttitle")->GetText());
3400 m_pURLED->DisableHistory();
3401 m_pFilePickerBtn->SetClickHdl( LINK( this, AddInstanceDialog, FilePickerHdl ) );
3403 // load the filter name from fps_office resource
3404 m_sAllFilterName = ResId(STR_FILTERNAME_ALL, *ResMgr::CreateResMgr("fps_office")).toString();
3407 AddInstanceDialog::~AddInstanceDialog()
3409 disposeOnce();
3412 void AddInstanceDialog::dispose()
3414 m_pNameED.clear();
3415 m_pURLFT.clear();
3416 m_pURLED.clear();
3417 m_pFilePickerBtn.clear();
3418 m_pLinkInstanceCB.clear();
3419 ModalDialog::dispose();
3422 IMPL_LINK_NOARG(AddInstanceDialog, FilePickerHdl)
3424 ::sfx2::FileDialogHelper aDlg(
3425 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
3426 INetURLObject aFile( SvtPathOptions().GetWorkPath() );
3428 aDlg.AddFilter( m_sAllFilterName, OUString(FILEDIALOG_FILTER_ALL) );
3429 OUString sFilterName( "XML" );
3430 aDlg.AddFilter( sFilterName, "*.xml" );
3431 aDlg.SetCurrentFilter( sFilterName );
3432 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
3434 if( aDlg.Execute() == ERRCODE_NONE )
3435 m_pURLED->SetText( aDlg.GetPath() );
3437 return 0;
3440 LinkedInstanceWarningBox::LinkedInstanceWarningBox( vcl::Window* pParent )
3441 : MessageDialog(pParent, "FormLinkWarnDialog", "svx/ui/formlinkwarndialog.ui")
3447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */