lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / svx / source / form / datanavi.cxx
blobca3acd9f2a9e62654e491fc96637d10f8b5cacbb
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 SfxDockingWindow::dispose();
2183 void DataNavigator::StateChanged( sal_uInt16 , SfxItemState , const SfxPoolItem* )
2188 void DataNavigator::GetFocus()
2190 SfxDockingWindow::GetFocus();
2194 bool DataNavigator::Close()
2196 return SfxDockingWindow::Close();
2200 Size DataNavigator::CalcDockingSize( SfxChildAlignment eAlign )
2202 if ( ( eAlign == SfxChildAlignment::TOP ) || ( eAlign == SfxChildAlignment::BOTTOM ) )
2203 return Size();
2205 return SfxDockingWindow::CalcDockingSize( eAlign );
2209 SfxChildAlignment DataNavigator::CheckAlignment( SfxChildAlignment eActAlign, SfxChildAlignment eAlign )
2211 switch ( eAlign )
2213 case SfxChildAlignment::LEFT:
2214 case SfxChildAlignment::RIGHT:
2215 case SfxChildAlignment::NOALIGNMENT:
2216 return eAlign;
2217 default:
2218 break;
2220 return eActAlign;
2224 void DataNavigator::Resize()
2226 SfxDockingWindow::Resize();
2228 Size aLogOutputSize = PixelToLogic( GetOutputSizePixel(), MAP_APPFONT );
2229 Size aLogExplSize = aLogOutputSize;
2230 aLogExplSize.Width() -= 2;
2231 aLogExplSize.Height() -= 2;
2233 Point aExplPos = LogicToPixel( Point(1,1), MAP_APPFONT );
2234 Size aExplSize = LogicToPixel( aLogExplSize, MAP_APPFONT );
2236 m_aDataWin->SetPosSizePixel( aExplPos, aExplSize );
2241 // class NavigatorFrameManager
2245 SFX_IMPL_DOCKINGWINDOW( DataNavigatorManager, SID_FM_SHOW_DATANAVIGATOR )
2248 DataNavigatorManager::DataNavigatorManager(
2249 vcl::Window* _pParent, sal_uInt16 _nId, SfxBindings* _pBindings, SfxChildWinInfo* _pInfo ) :
2251 SfxChildWindow( _pParent, _nId )
2254 pWindow = VclPtr<DataNavigator>::Create( _pBindings, this, _pParent );
2255 eChildAlignment = SfxChildAlignment::RIGHT;
2256 pWindow->SetSizePixel( Size( 250, 400 ) );
2257 static_cast<SfxDockingWindow*>(pWindow.get())->Initialize( _pInfo );
2260 AddDataItemDialog::AddDataItemDialog(vcl::Window* pParent, ItemNode* _pNode,
2261 const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper)
2262 : ModalDialog(pParent, "AddDataItemDialog" , "svx/ui/adddataitemdialog.ui")
2263 , m_xUIHelper(_rUIHelper)
2264 , m_pItemNode(_pNode)
2265 , m_eItemType(DITNone)
2266 , m_sFL_Element(SVX_RESSTR(RID_STR_ELEMENT))
2267 , m_sFL_Attribute(SVX_RESSTR(RID_STR_ATTRIBUTE))
2268 , m_sFL_Binding(SVX_RESSTR(RID_STR_BINDING))
2269 , m_sFT_BindingExp(SVX_RESSTR(RID_STR_BINDING_EXPR))
2271 get(m_pItemFrame, "itemframe");
2272 get(m_pNameFT, "nameft");
2273 get(m_pNameED, "name");
2274 get(m_pDefaultFT, "valueft");
2275 get(m_pDefaultED, "value");
2276 get(m_pDefaultBtn, "browse");
2277 get(m_pSettingsFrame, "settingsframe");
2278 get(m_pDataTypeFT, "datatypeft");
2279 get(m_pDataTypeLB, "datatype");
2280 get(m_pRequiredCB, "required");
2281 get(m_pRequiredBtn, "requiredcond");
2282 get(m_pRelevantCB, "relevant");
2283 get(m_pRelevantBtn, "relevantcond");
2284 get(m_pConstraintCB, "constraint");
2285 get(m_pConstraintBtn, "constraintcond");
2286 get(m_pReadonlyCB, "readonly");
2287 get(m_pReadonlyBtn, "readonlycond");
2288 get(m_pCalculateCB, "calculate");
2289 get(m_pCalculateBtn, "calculatecond");
2290 get(m_pOKBtn, "ok");
2291 m_pDataTypeLB->SetDropDownLineCount( 10 );
2293 InitDialog();
2294 InitFromNode();
2295 InitDataTypeBox();
2296 CheckHdl( NULL );
2300 AddDataItemDialog::~AddDataItemDialog()
2302 disposeOnce();
2305 void AddDataItemDialog::dispose()
2307 if ( m_xTempBinding.is() )
2309 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2310 if ( xModel.is() )
2314 Reference < XSet > xBindings = xModel->getBindings();
2315 if ( xBindings.is() )
2316 xBindings->remove( makeAny( m_xTempBinding ) );
2318 catch (const Exception&)
2320 SAL_WARN( "svx.form", "AddDataItemDialog::Dtor(): exception caught" );
2324 if( m_xUIHelper.is() && m_xBinding.is() )
2326 // remove binding, if it does not convey 'useful' information
2327 m_xUIHelper->removeBindingIfUseless( m_xBinding );
2329 m_pItemFrame.clear();
2330 m_pNameFT.clear();
2331 m_pNameED.clear();
2332 m_pDefaultFT.clear();
2333 m_pDefaultED.clear();
2334 m_pDefaultBtn.clear();
2335 m_pSettingsFrame.clear();
2336 m_pDataTypeFT.clear();
2337 m_pDataTypeLB.clear();
2338 m_pRequiredCB.clear();
2339 m_pRequiredBtn.clear();
2340 m_pRelevantCB.clear();
2341 m_pRelevantBtn.clear();
2342 m_pConstraintCB.clear();
2343 m_pConstraintBtn.clear();
2344 m_pReadonlyCB.clear();
2345 m_pReadonlyBtn.clear();
2346 m_pCalculateCB.clear();
2347 m_pCalculateBtn.clear();
2348 m_pOKBtn.clear();
2349 ModalDialog::dispose();
2353 IMPL_LINK( AddDataItemDialog, CheckHdl, CheckBox *, pBox )
2355 // Condition buttons are only enable if their check box is checked
2356 m_pReadonlyBtn->Enable( m_pReadonlyCB->IsChecked() );
2357 m_pRequiredBtn->Enable( m_pRequiredCB->IsChecked() );
2358 m_pRelevantBtn->Enable( m_pRelevantCB->IsChecked() );
2359 m_pConstraintBtn->Enable( m_pConstraintCB->IsChecked() );
2360 m_pCalculateBtn->Enable( m_pCalculateCB->IsChecked() );
2362 if ( pBox && m_xTempBinding.is() )
2364 OUString sTemp, sPropName;
2365 if ( m_pRequiredCB == pBox )
2366 sPropName = PN_REQUIRED_EXPR;
2367 else if ( m_pRelevantCB == pBox )
2368 sPropName = PN_RELEVANT_EXPR;
2369 else if ( m_pConstraintCB == pBox )
2370 sPropName = PN_CONSTRAINT_EXPR;
2371 else if ( m_pReadonlyCB == pBox )
2372 sPropName = PN_READONLY_EXPR;
2373 else if ( m_pCalculateCB == pBox )
2374 sPropName = PN_CALCULATE_EXPR;
2375 bool bIsChecked = pBox->IsChecked();
2376 m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp;
2377 if ( bIsChecked && sTemp.isEmpty() )
2378 sTemp = TRUE_VALUE;
2379 else if ( !bIsChecked && !sTemp.isEmpty() )
2380 sTemp.clear();
2381 m_xTempBinding->setPropertyValue( sPropName, makeAny( sTemp ) );
2384 return 0;
2388 IMPL_LINK( AddDataItemDialog, ConditionHdl, PushButton *, pBtn )
2390 OUString sTemp, sPropName;
2391 if ( m_pDefaultBtn == pBtn )
2392 sPropName = PN_BINDING_EXPR;
2393 else if ( m_pRequiredBtn == pBtn )
2394 sPropName = PN_REQUIRED_EXPR;
2395 else if ( m_pRelevantBtn == pBtn )
2396 sPropName = PN_RELEVANT_EXPR;
2397 else if ( m_pConstraintBtn == pBtn )
2398 sPropName = PN_CONSTRAINT_EXPR;
2399 else if (m_pReadonlyBtn == pBtn)
2400 sPropName = PN_READONLY_EXPR;
2401 else if (m_pCalculateBtn == pBtn)
2402 sPropName = PN_CALCULATE_EXPR;
2403 ScopedVclPtrInstance< AddConditionDialog > aDlg(this, sPropName, m_xTempBinding);
2404 bool bIsDefBtn = ( m_pDefaultBtn == pBtn );
2405 OUString sCondition;
2406 if ( bIsDefBtn )
2407 sCondition = m_pDefaultED->GetText();
2408 else
2410 m_xTempBinding->getPropertyValue( sPropName ) >>= sTemp;
2411 if ( sTemp.isEmpty() )
2412 sTemp = TRUE_VALUE;
2413 sCondition = sTemp;
2415 aDlg->SetCondition( sCondition );
2417 if ( aDlg->Execute() == RET_OK )
2419 OUString sNewCondition = aDlg->GetCondition();
2420 if ( bIsDefBtn )
2421 m_pDefaultED->SetText( sNewCondition );
2422 else
2425 m_xTempBinding->setPropertyValue(
2426 sPropName, makeAny( OUString( sNewCondition ) ) );
2429 return 0;
2432 void copyPropSet( const Reference< XPropertySet >& xFrom, Reference< XPropertySet >& xTo )
2434 DBG_ASSERT( xFrom.is(), "copyPropSet(): no source" );
2435 DBG_ASSERT( xTo.is(), "copyPropSet(): no target" );
2439 // get property names & infos, and iterate over target properties
2440 Sequence< Property > aProperties = xTo->getPropertySetInfo()->getProperties();
2441 sal_Int32 nProperties = aProperties.getLength();
2442 const Property* pProperties = aProperties.getConstArray();
2443 Reference< XPropertySetInfo > xFromInfo = xFrom->getPropertySetInfo();
2444 for ( sal_Int32 i = 0; i < nProperties; ++i )
2446 const OUString& rName = pProperties[i].Name;
2448 // if both set have the property, copy the value
2449 // (catch and ignore exceptions, if any)
2450 if ( xFromInfo->hasPropertyByName( rName ) )
2452 // don't set readonly properties
2453 Property aProperty = xFromInfo->getPropertyByName( rName );
2454 if ( ( aProperty.Attributes & PropertyAttribute::READONLY ) == 0 )
2455 xTo->setPropertyValue(rName, xFrom->getPropertyValue( rName ));
2457 // else: no property? then ignore.
2460 catch ( Exception& )
2462 SAL_WARN( "svx.form", "copyPropSet(): exception caught" );
2467 IMPL_LINK_NOARG(AddDataItemDialog, OKHdl)
2469 bool bIsHandleBinding = ( DITBinding == m_eItemType );
2470 bool bIsHandleText = ( DITText == m_eItemType );
2471 OUString sNewName( m_pNameED->GetText() );
2473 if ( ( !bIsHandleBinding && !bIsHandleText && !m_xUIHelper->isValidXMLName( sNewName ) ) ||
2474 ( bIsHandleBinding && sNewName.isEmpty() ) )
2476 // Error and don't close the dialog
2477 ScopedVclPtrInstance< MessageDialog > aErrBox( this, SVX_RES( RID_STR_INVALID_XMLNAME ) );
2478 aErrBox->set_primary_text(aErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sNewName));
2479 aErrBox->Execute();
2480 return 0;
2483 OUString sDataType( m_pDataTypeLB->GetSelectEntry() );
2484 m_xTempBinding->setPropertyValue( PN_BINDING_TYPE, makeAny( sDataType ) );
2486 if ( bIsHandleBinding )
2488 // copy properties from temp binding to original binding
2489 copyPropSet( m_xTempBinding, m_pItemNode->m_xPropSet );
2492 OUString sValue = m_pNameED->GetText();
2493 m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_ID, makeAny( sValue ) );
2494 sValue = m_pDefaultED->GetText();
2495 m_pItemNode->m_xPropSet->setPropertyValue( PN_BINDING_EXPR, makeAny( sValue ) );
2497 catch ( Exception& )
2499 SAL_WARN( "svx.form", "AddDataDialog::OKHdl(): exception caught" );
2502 else
2504 // copy properties from temp binding to original binding
2505 copyPropSet( m_xTempBinding, m_xBinding );
2508 if ( bIsHandleText )
2509 m_xUIHelper->setNodeValue( m_pItemNode->m_xNode, m_pDefaultED->GetText() );
2510 else
2512 Reference< css::xml::dom::XNode > xNewNode =
2513 m_xUIHelper->renameNode( m_pItemNode->m_xNode, m_pNameED->GetText() );
2514 m_xUIHelper->setNodeValue( xNewNode, m_pDefaultED->GetText() );
2515 m_pItemNode->m_xNode = xNewNode;
2518 catch ( Exception& )
2520 SAL_WARN( "svx.form", "AddDataDialog::OKHdl(): exception caught" );
2523 // then close the dialog
2524 EndDialog( RET_OK );
2525 return 0;
2529 void AddDataItemDialog::InitDialog()
2531 // set handler
2532 Link<> aLink = LINK( this, AddDataItemDialog, CheckHdl );
2533 m_pRequiredCB->SetClickHdl( aLink );
2534 m_pRelevantCB->SetClickHdl( aLink );
2535 m_pConstraintCB->SetClickHdl( aLink );
2536 m_pReadonlyCB->SetClickHdl( aLink );
2537 m_pCalculateCB->SetClickHdl( aLink );
2539 aLink = LINK( this, AddDataItemDialog, ConditionHdl );
2540 m_pDefaultBtn->SetClickHdl( aLink );
2541 m_pRequiredBtn->SetClickHdl( aLink );
2542 m_pRelevantBtn->SetClickHdl( aLink );
2543 m_pConstraintBtn->SetClickHdl( aLink );
2544 m_pReadonlyBtn->SetClickHdl( aLink );
2545 m_pCalculateBtn->SetClickHdl( aLink );
2547 m_pOKBtn->SetClickHdl( LINK( this, AddDataItemDialog, OKHdl ) );
2551 void AddDataItemDialog::InitFromNode()
2553 if ( m_pItemNode )
2555 if ( m_pItemNode->m_xNode.is() )
2559 // detect type of the node
2560 css::xml::dom::NodeType eChildType = m_pItemNode->m_xNode->getNodeType();
2561 switch ( eChildType )
2563 case css::xml::dom::NodeType_ATTRIBUTE_NODE:
2564 m_eItemType = DITAttribute;
2565 break;
2566 case css::xml::dom::NodeType_ELEMENT_NODE:
2567 m_eItemType = DITElement;
2568 break;
2569 case css::xml::dom::NodeType_TEXT_NODE:
2570 m_eItemType = DITText;
2571 break;
2572 default:
2573 OSL_FAIL( "AddDataItemDialog::InitFronNode: cannot handle this node type!" );
2574 break;
2577 /** Get binding of the node and clone it
2578 Then use this temporary binding in the dialog.
2579 When the user click OK the temporary binding will be copied
2580 into the original binding.
2583 Reference< css::xml::dom::XNode > xNode = m_pItemNode->m_xNode;
2584 m_xBinding = m_xUIHelper->getBindingForNode( xNode, sal_True );
2585 if ( m_xBinding.is() )
2587 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2588 if ( xModel.is() )
2590 m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_xBinding );
2591 Reference < XSet > xBindings = xModel->getBindings();
2592 if ( xBindings.is() )
2593 xBindings->insert( makeAny( m_xTempBinding ) );
2597 if ( m_eItemType != DITText )
2599 OUString sName( m_xUIHelper->getNodeName( m_pItemNode->m_xNode ) );
2600 m_pNameED->SetText( sName );
2602 m_pDefaultED->SetText( m_pItemNode->m_xNode->getNodeValue() );
2604 catch( Exception& )
2606 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2609 else if ( m_pItemNode->m_xPropSet.is() )
2611 m_eItemType = DITBinding;
2612 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2613 if ( xModel.is() )
2617 m_xTempBinding = m_xUIHelper->cloneBindingAsGhost( m_pItemNode->m_xPropSet );
2618 Reference < XSet > xBindings = xModel->getBindings();
2619 if ( xBindings.is() )
2620 xBindings->insert( makeAny( m_xTempBinding ) );
2622 catch ( Exception& )
2624 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2627 OUString sTemp;
2630 Reference< XPropertySetInfo > xInfo = m_pItemNode->m_xPropSet->getPropertySetInfo();
2631 if ( xInfo->hasPropertyByName( PN_BINDING_ID ) )
2633 m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
2634 m_pNameED->SetText( sTemp );
2635 m_pItemNode->m_xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
2636 m_pDefaultED->SetText( sTemp );
2638 else if ( xInfo->hasPropertyByName( PN_SUBMISSION_BIND ) )
2640 m_pItemNode->m_xPropSet->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
2641 m_pNameED->SetText( sTemp );
2644 catch( Exception& )
2646 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2649 Size a3and1Sz = LogicToPixel( Size( 3, 1 ), MAP_APPFONT );
2650 Size aNewSz = m_pDefaultED->GetSizePixel();
2651 Point aNewPnt = m_pDefaultED->GetPosPixel();
2652 aNewPnt.Y() += a3and1Sz.Height();
2653 aNewSz.Width() -= ( m_pDefaultBtn->GetSizePixel().Width() + a3and1Sz.Width() );
2654 m_pDefaultED->SetPosSizePixel( aNewPnt, aNewSz );
2655 m_pDefaultBtn->Show();
2658 if ( m_xTempBinding.is() )
2660 OUString sTemp;
2663 if ( ( m_xTempBinding->getPropertyValue( PN_REQUIRED_EXPR ) >>= sTemp )
2664 && !sTemp.isEmpty() )
2665 m_pRequiredCB->Check( true );
2666 if ( ( m_xTempBinding->getPropertyValue( PN_RELEVANT_EXPR ) >>= sTemp )
2667 && !sTemp.isEmpty() )
2668 m_pRelevantCB->Check( true );
2669 if ( ( m_xTempBinding->getPropertyValue( PN_CONSTRAINT_EXPR ) >>= sTemp )
2670 && !sTemp.isEmpty() )
2671 m_pConstraintCB->Check( true );
2672 if ( ( m_xTempBinding->getPropertyValue( PN_READONLY_EXPR ) >>= sTemp )
2673 && !sTemp.isEmpty() )
2674 m_pReadonlyCB->Check( true );
2675 if ( ( m_xTempBinding->getPropertyValue( PN_CALCULATE_EXPR ) >>= sTemp )
2676 && !sTemp.isEmpty() )
2677 m_pCalculateCB->Check( true );
2679 catch (const Exception&)
2681 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2686 if ( DITText == m_eItemType )
2688 m_pSettingsFrame->Hide();
2689 m_pNameFT->Disable();
2690 m_pNameED->Disable();
2695 void AddDataItemDialog::InitDataTypeBox()
2697 if ( m_eItemType != DITText )
2699 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
2700 if ( xModel.is() )
2704 Reference< css::xforms::XDataTypeRepository > xDataTypes =
2705 xModel->getDataTypeRepository();
2706 if ( xDataTypes.is() )
2708 Sequence< OUString > aNameList = xDataTypes->getElementNames();
2709 sal_Int32 i, nCount = aNameList.getLength();
2710 OUString* pNames = aNameList.getArray();
2711 for ( i = 0; i < nCount; ++i )
2712 m_pDataTypeLB->InsertEntry( pNames[i] );
2715 if ( m_xTempBinding.is() )
2717 OUString sTemp;
2718 if ( m_xTempBinding->getPropertyValue( PN_BINDING_TYPE ) >>= sTemp )
2720 sal_Int32 nPos = m_pDataTypeLB->GetEntryPos( sTemp );
2721 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
2722 nPos = m_pDataTypeLB->InsertEntry( sTemp );
2723 m_pDataTypeLB->SelectEntryPos( nPos );
2727 catch ( Exception& )
2729 SAL_WARN( "svx.form", "AddDataItemDialog::InitDataTypeBox(): exception caught" );
2735 void AddDataItemDialog::InitText( DataItemType _eType )
2737 OUString sText;
2739 switch ( _eType )
2741 case DITAttribute :
2743 sText = m_sFL_Attribute;
2744 break;
2747 case DITBinding :
2749 sText = m_sFL_Binding;
2750 m_pDefaultFT->SetText( m_sFT_BindingExp );
2751 break;
2754 default:
2756 sText = m_sFL_Element;
2760 m_pItemFrame->set_label(sText);
2763 AddConditionDialog::AddConditionDialog(vcl::Window* pParent,
2764 const OUString& _rPropertyName,
2765 const Reference< XPropertySet >& _rPropSet)
2766 : ModalDialog(pParent, "AddConditionDialog", "svx/ui/addconditiondialog.ui")
2767 , m_sPropertyName(_rPropertyName)
2768 , m_xBinding(_rPropSet)
2771 get(m_pConditionED, "condition");
2772 get(m_pResultWin, "result");
2773 get(m_pEditNamespacesBtn, "edit");
2774 get(m_pOKBtn, "ok");
2775 DBG_ASSERT( m_xBinding.is(), "AddConditionDialog::Ctor(): no Binding" );
2777 m_pConditionED->set_height_request(m_pConditionED->GetTextHeight() * 4);
2778 m_pConditionED->set_width_request(m_pConditionED->approximate_char_width() * 62);
2779 m_pResultWin->set_height_request(m_pResultWin->GetTextHeight() * 4);
2780 m_pResultWin->set_width_request(m_pResultWin->approximate_char_width() * 62);
2782 m_pConditionED->SetModifyHdl( LINK( this, AddConditionDialog, ModifyHdl ) );
2783 m_pEditNamespacesBtn->SetClickHdl( LINK( this, AddConditionDialog, EditHdl ) );
2784 m_pOKBtn->SetClickHdl( LINK( this, AddConditionDialog, OKHdl ) );
2785 m_aResultIdle.SetPriority( SchedulerPriority::LOWEST );
2786 m_aResultIdle.SetIdleHdl( LINK( this, AddConditionDialog, ResultHdl ) );
2788 if ( !m_sPropertyName.isEmpty() )
2792 OUString sTemp;
2793 if ( ( m_xBinding->getPropertyValue( m_sPropertyName ) >>= sTemp )
2794 && !sTemp.isEmpty() )
2796 m_pConditionED->SetText( sTemp );
2798 else
2800 //! m_xBinding->setPropertyValue( m_sPropertyName, makeAny( TRUE_VALUE ) );
2801 m_pConditionED->SetText( TRUE_VALUE );
2804 Reference< css::xforms::XModel > xModel;
2805 if ( ( m_xBinding->getPropertyValue( PN_BINDING_MODEL ) >>= xModel ) && xModel.is() )
2806 m_xUIHelper = Reference< css::xforms::XFormsUIHelper1 >( xModel, UNO_QUERY );
2808 catch (const Exception&)
2810 SAL_WARN( "svx.form", "AddConditionDialog::Ctor(): exception caught" );
2814 DBG_ASSERT( m_xUIHelper.is(), "AddConditionDialog::Ctor(): no UIHelper" );
2815 ResultHdl( &m_aResultIdle );
2818 AddConditionDialog::~AddConditionDialog()
2820 disposeOnce();
2823 void AddConditionDialog::dispose()
2825 m_pConditionED.clear();
2826 m_pResultWin.clear();
2827 m_pEditNamespacesBtn.clear();
2828 m_pOKBtn.clear();
2829 ModalDialog::dispose();
2832 IMPL_LINK_NOARG(AddConditionDialog, EditHdl)
2834 Reference< XNameContainer > xNameContnr;
2837 m_xBinding->getPropertyValue( PN_BINDING_NAMESPACES ) >>= xNameContnr;
2839 catch ( Exception& )
2841 SAL_WARN( "svx.form", "AddDataItemDialog::EditHdl(): exception caught" );
2843 ScopedVclPtrInstance< NamespaceItemDialog > aDlg( this, xNameContnr );
2844 aDlg->Execute();
2847 m_xBinding->setPropertyValue( PN_BINDING_NAMESPACES, makeAny( xNameContnr ) );
2849 catch ( Exception& )
2851 SAL_WARN( "svx.form", "AddDataItemDialog::EditHdl(): exception caught" );
2853 return 0;
2857 IMPL_LINK_NOARG(AddConditionDialog, OKHdl)
2859 /*!!!
2862 if ( m_xBinding.is() )
2863 m_xBinding->setPropertyValue( m_sPropertyName, makeAny( OUString( m_pConditionED->GetText() ) ) );
2865 catch( const Exception& )
2867 SAL_WARN( "svx.form", "AddConditionDialog, OKHdl: caught an exception!" );
2870 EndDialog( RET_OK );
2871 return 0;
2875 IMPL_LINK_NOARG(AddConditionDialog, ModifyHdl)
2877 m_aResultIdle.Start();
2878 return 0;
2882 IMPL_LINK_NOARG_TYPED(AddConditionDialog, ResultHdl, Idle *, void)
2884 OUString sCondition = comphelper::string::strip(m_pConditionED->GetText(), ' ');
2885 OUString sResult;
2886 if ( !sCondition.isEmpty() )
2890 sResult = m_xUIHelper->getResultForExpression( m_xBinding, ( m_sPropertyName == PN_BINDING_EXPR ), sCondition );
2892 catch ( Exception& )
2894 SAL_WARN( "svx.form", "AddConditionDialog::ResultHdl(): exception caught" );
2897 m_pResultWin->SetText( sResult );
2900 NamespaceItemDialog::NamespaceItemDialog(
2901 AddConditionDialog* _pCondDlg,
2902 Reference< XNameContainer >& _rContainer )
2903 : ModalDialog( _pCondDlg, "NamespaceDialog",
2904 "svx/ui/namespacedialog.ui" )
2905 , m_pConditionDlg(_pCondDlg)
2906 , m_rNamespaces(_rContainer)
2908 get(m_pAddNamespaceBtn, "add");
2909 get(m_pEditNamespaceBtn, "edit");
2910 get(m_pDeleteNamespaceBtn, "delete");
2911 get(m_pOKBtn, "ok");
2913 SvSimpleTableContainer* pNamespacesListContainer =
2914 get<SvSimpleTableContainer>("namespaces");
2915 Size aControlSize(175, 72);
2916 aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
2917 pNamespacesListContainer->set_width_request(aControlSize.Width());
2918 pNamespacesListContainer->set_height_request(aControlSize.Height());
2919 m_pNamespacesList = VclPtr<SvSimpleTable>::Create(*pNamespacesListContainer, 0);
2921 static long aStaticTabs[]= { 3, 0, 35, 200 };
2922 m_pNamespacesList->SvSimpleTable::SetTabs( aStaticTabs );
2923 OUString sHeader = get<FixedText>("prefix")->GetText();
2924 sHeader += "\t";
2925 sHeader += get<FixedText>("url")->GetText();
2926 m_pNamespacesList->InsertHeaderEntry(
2927 sHeader, HEADERBAR_APPEND, HeaderBarItemBits::LEFT /*| HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::FIXED*/ );
2929 m_pNamespacesList->SetSelectHdl( LINK( this, NamespaceItemDialog, SelectHdl ) );
2930 Link<> aLink = LINK( this, NamespaceItemDialog, ClickHdl );
2931 m_pAddNamespaceBtn->SetClickHdl( aLink );
2932 m_pEditNamespaceBtn->SetClickHdl( aLink );
2933 m_pDeleteNamespaceBtn->SetClickHdl( aLink );
2934 m_pOKBtn->SetClickHdl( LINK( this, NamespaceItemDialog, OKHdl ) );
2936 LoadNamespaces();
2937 SelectHdl( m_pNamespacesList );
2941 NamespaceItemDialog::~NamespaceItemDialog()
2943 disposeOnce();
2946 void NamespaceItemDialog::dispose()
2948 m_pNamespacesList.disposeAndClear();
2949 m_pAddNamespaceBtn.clear();
2950 m_pEditNamespaceBtn.clear();
2951 m_pDeleteNamespaceBtn.clear();
2952 m_pOKBtn.clear();
2953 m_pConditionDlg.clear();
2954 ModalDialog::dispose();
2958 IMPL_LINK( NamespaceItemDialog, SelectHdl, SvSimpleTable *, )
2960 bool bEnable = ( m_pNamespacesList->FirstSelected() != NULL );
2961 m_pEditNamespaceBtn->Enable( bEnable );
2962 m_pDeleteNamespaceBtn->Enable( bEnable );
2964 return 0;
2968 IMPL_LINK( NamespaceItemDialog, ClickHdl, PushButton *, pBtn )
2970 if ( m_pAddNamespaceBtn == pBtn )
2972 ScopedVclPtrInstance< ManageNamespaceDialog > aDlg(this, m_pConditionDlg, false);
2973 if ( aDlg->Execute() == RET_OK )
2975 OUString sEntry = aDlg->GetPrefix();
2976 sEntry += "\t";
2977 sEntry += aDlg->GetURL();
2978 m_pNamespacesList->InsertEntry( sEntry );
2981 else if ( m_pEditNamespaceBtn == pBtn )
2983 ScopedVclPtrInstance< ManageNamespaceDialog > aDlg( this, m_pConditionDlg, true );
2984 SvTreeListEntry* pEntry = m_pNamespacesList->FirstSelected();
2985 DBG_ASSERT( pEntry, "NamespaceItemDialog::ClickHdl(): no entry" );
2986 OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
2987 aDlg->SetNamespace(
2988 sPrefix,
2989 SvTabListBox::GetEntryText( pEntry, 1 ) );
2990 if ( aDlg->Execute() == RET_OK )
2992 // if a prefix was changed, mark the old prefix as 'removed'
2993 if( sPrefix != aDlg->GetPrefix() )
2994 m_aRemovedList.push_back( sPrefix );
2996 m_pNamespacesList->SetEntryText( aDlg->GetPrefix(), pEntry, 0 );
2997 m_pNamespacesList->SetEntryText( aDlg->GetURL(), pEntry, 1 );
3000 else if ( m_pDeleteNamespaceBtn == pBtn )
3002 SvTreeListEntry* pEntry = m_pNamespacesList->FirstSelected();
3003 DBG_ASSERT( pEntry, "NamespaceItemDialog::ClickHdl(): no entry" );
3004 OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
3005 m_aRemovedList.push_back( sPrefix );
3006 m_pNamespacesList->GetModel()->Remove( pEntry );
3008 else
3010 SAL_WARN( "svx.form", "NamespaceItemDialog::ClickHdl(): invalid button" );
3013 SelectHdl( m_pNamespacesList );
3014 return 0;
3018 IMPL_LINK_NOARG(NamespaceItemDialog, OKHdl)
3022 // update namespace container
3023 sal_Int32 i, nRemovedCount = m_aRemovedList.size();
3024 for( i = 0; i < nRemovedCount; ++i )
3025 m_rNamespaces->removeByName( m_aRemovedList[i] );
3027 sal_Int32 nEntryCount = m_pNamespacesList->GetEntryCount();
3028 for( i = 0; i < nEntryCount; ++i )
3030 SvTreeListEntry* pEntry = m_pNamespacesList->GetEntry(i);
3031 OUString sPrefix( SvTabListBox::GetEntryText( pEntry, 0 ) );
3032 OUString sURL( SvTabListBox::GetEntryText( pEntry, 1 ) );
3034 if ( m_rNamespaces->hasByName( sPrefix ) )
3035 m_rNamespaces->replaceByName( sPrefix, makeAny( sURL ) );
3036 else
3037 m_rNamespaces->insertByName( sPrefix, makeAny( sURL ) );
3040 catch ( Exception& )
3042 SAL_WARN( "svx.form", "NamespaceItemDialog::OKHdl(): exception caught" );
3044 // and close the dialog
3045 EndDialog( RET_OK );
3046 return 0;
3050 void NamespaceItemDialog::LoadNamespaces()
3054 Sequence< OUString > aAllNames = m_rNamespaces->getElementNames();
3055 const OUString* pAllNames = aAllNames.getConstArray();
3056 const OUString* pAllNamesEnd = pAllNames + aAllNames.getLength();
3057 for ( ; pAllNames != pAllNamesEnd; ++pAllNames )
3059 OUString sURL;
3060 OUString sPrefix = *pAllNames;
3061 if ( m_rNamespaces->hasByName( sPrefix ) )
3063 Any aAny = m_rNamespaces->getByName( sPrefix );
3064 if ( aAny >>= sURL )
3066 OUString sEntry( sPrefix );
3067 sEntry += "\t";
3068 sEntry += sURL;
3070 m_pNamespacesList->InsertEntry( sEntry );
3075 catch ( Exception& )
3077 SAL_WARN( "svx.form", "NamespaceItemDialog::LoadNamespaces(): exception caught" );
3081 ManageNamespaceDialog::ManageNamespaceDialog(vcl::Window* pParent, AddConditionDialog* _pCondDlg, bool bIsEdit)
3082 : ModalDialog(pParent, "AddNamespaceDialog", "svx/ui/addnamespacedialog.ui")
3083 , m_pConditionDlg ( _pCondDlg )
3085 get(m_pOKBtn, "ok");
3086 get(m_pPrefixED, "prefix");
3087 get(m_pUrlED, "url");
3089 if (bIsEdit)
3090 SetText(get<FixedText>("alttitle")->GetText());
3092 m_pOKBtn->SetClickHdl( LINK( this, ManageNamespaceDialog, OKHdl ) );
3095 ManageNamespaceDialog::~ManageNamespaceDialog()
3097 disposeOnce();
3100 void ManageNamespaceDialog::dispose()
3102 m_pOKBtn.clear();
3103 m_pPrefixED.clear();
3104 m_pUrlED.clear();
3105 m_pConditionDlg.clear();
3106 ModalDialog::dispose();
3109 IMPL_LINK_NOARG(ManageNamespaceDialog, OKHdl)
3111 OUString sPrefix = m_pPrefixED->GetText();
3115 if ( !m_pConditionDlg->GetUIHelper()->isValidPrefixName( sPrefix ) )
3117 ScopedVclPtrInstance< MessageDialog > aErrBox(this, SVX_RES( RID_STR_INVALID_XMLPREFIX ) );
3118 aErrBox->set_primary_text(aErrBox->get_primary_text().replaceFirst(MSG_VARIABLE, sPrefix));
3119 aErrBox->Execute();
3120 return 0;
3123 catch ( Exception& )
3125 SAL_WARN( "svx.form", "ManageNamespacesDialog::OKHdl(): exception caught" );
3128 // no error so close the dialog
3129 EndDialog( RET_OK );
3130 return 0;
3133 AddSubmissionDialog::AddSubmissionDialog(
3134 vcl::Window* pParent, ItemNode* _pNode,
3135 const Reference< css::xforms::XFormsUIHelper1 >& _rUIHelper)
3136 : ModalDialog(pParent, "AddSubmissionDialog",
3137 "svx/ui/addsubmissiondialog.ui")
3138 , m_pItemNode(_pNode)
3139 , m_xUIHelper(_rUIHelper)
3141 get(m_pNameED, "name");
3142 get(m_pActionED, "action");
3143 get(m_pMethodLB, "method");
3144 get(m_pRefED, "expression");
3145 get(m_pRefBtn, "browse");
3146 get(m_pBindLB, "binding");
3147 get(m_pReplaceLB, "replace");
3148 get(m_pOKBtn, "ok");
3149 FillAllBoxes();
3151 m_pRefBtn->SetClickHdl( LINK( this, AddSubmissionDialog, RefHdl ) );
3152 m_pOKBtn->SetClickHdl( LINK( this, AddSubmissionDialog, OKHdl ) );
3156 AddSubmissionDialog::~AddSubmissionDialog()
3158 disposeOnce();
3161 void AddSubmissionDialog::dispose()
3163 // #i38991# if we have added a binding, we need to remove it as well.
3164 if( m_xCreatedBinding.is() && m_xUIHelper.is() )
3165 m_xUIHelper->removeBindingIfUseless( m_xCreatedBinding );
3166 m_pNameED.clear();
3167 m_pActionED.clear();
3168 m_pMethodLB.clear();
3169 m_pRefED.clear();
3170 m_pRefBtn.clear();
3171 m_pBindLB.clear();
3172 m_pReplaceLB.clear();
3173 m_pOKBtn.clear();
3174 ModalDialog::dispose();
3178 IMPL_LINK_NOARG(AddSubmissionDialog, RefHdl)
3180 ScopedVclPtrInstance< AddConditionDialog > aDlg(this, PN_BINDING_EXPR, m_xTempBinding );
3181 aDlg->SetCondition( m_pRefED->GetText() );
3182 if ( aDlg->Execute() == RET_OK )
3183 m_pRefED->SetText( aDlg->GetCondition() );
3185 return 0;
3189 IMPL_LINK_NOARG(AddSubmissionDialog, OKHdl)
3191 OUString sName(m_pNameED->GetText());
3192 if(sName.isEmpty()) {
3194 ScopedVclPtrInstance< MessageDialog > aErrorBox(this,SVX_RES(RID_STR_EMPTY_SUBMISSIONNAME));
3195 aErrorBox->set_primary_text( Application::GetDisplayName() );
3196 aErrorBox->Execute();
3197 return 0;
3200 if ( !m_xSubmission.is() )
3202 DBG_ASSERT( !m_xNewSubmission.is(),
3203 "AddSubmissionDialog::OKHdl(): new submission already exists" );
3205 // add a new submission
3206 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
3207 if ( xModel.is() )
3211 m_xNewSubmission = xModel->createSubmission();
3212 m_xSubmission = Reference< XPropertySet >( m_xNewSubmission, UNO_QUERY );
3214 catch ( Exception& )
3216 SAL_WARN( "svx.form", "AddSubmissionDialog::OKHdl(): exception caught" );
3221 if ( m_xSubmission.is() )
3223 OUString sTemp = m_pNameED->GetText();
3226 m_xSubmission->setPropertyValue( PN_SUBMISSION_ID, makeAny( sTemp ) );
3227 sTemp = m_pActionED->GetText();
3228 m_xSubmission->setPropertyValue( PN_SUBMISSION_ACTION, makeAny( sTemp ) );
3229 sTemp = m_aMethodString.toAPI( m_pMethodLB->GetSelectEntry() );
3230 m_xSubmission->setPropertyValue( PN_SUBMISSION_METHOD, makeAny( sTemp ) );
3231 sTemp = m_pRefED->GetText();
3232 m_xSubmission->setPropertyValue( PN_SUBMISSION_REF, makeAny( sTemp ) );
3233 OUString sEntry = m_pBindLB->GetSelectEntry();
3234 sal_Int32 nColonIdx = sEntry.indexOf(':');
3235 if (nColonIdx != -1)
3236 sEntry = sEntry.copy(0, nColonIdx);
3237 sTemp = sEntry;
3238 m_xSubmission->setPropertyValue( PN_SUBMISSION_BIND, makeAny( sTemp ) );
3239 sTemp = m_aReplaceString.toAPI( m_pReplaceLB->GetSelectEntry() );
3240 m_xSubmission->setPropertyValue( PN_SUBMISSION_REPLACE, makeAny( sTemp ) );
3242 catch ( Exception& )
3244 SAL_WARN( "svx.form", "AddSubmissionDialog::OKHdl(): exception caught" );
3248 EndDialog( RET_OK );
3249 return 0;
3253 void AddSubmissionDialog::FillAllBoxes()
3255 // method box
3256 m_pMethodLB->InsertEntry( SVX_RESSTR( RID_STR_METHOD_POST ) );
3257 m_pMethodLB->InsertEntry( SVX_RESSTR( RID_STR_METHOD_PUT ) );
3258 m_pMethodLB->InsertEntry( SVX_RESSTR( RID_STR_METHOD_GET ) );
3259 m_pMethodLB->SelectEntryPos(0);
3261 // binding box
3262 Reference< css::xforms::XModel > xModel( m_xUIHelper, UNO_QUERY );
3263 if ( xModel.is() )
3267 Reference< XEnumerationAccess > xNumAccess( xModel->getBindings(), UNO_QUERY );
3268 if ( xNumAccess.is() )
3270 Reference < XEnumeration > xNum = xNumAccess->createEnumeration();
3271 if ( xNum.is() && xNum->hasMoreElements() )
3273 OUString sDelim( ": " );
3274 while ( xNum->hasMoreElements() )
3276 Reference< XPropertySet > xPropSet;
3277 Any aAny = xNum->nextElement();
3278 if ( aAny >>= xPropSet )
3280 OUString sEntry;
3281 OUString sTemp;
3282 xPropSet->getPropertyValue( PN_BINDING_ID ) >>= sTemp;
3283 sEntry += sTemp;
3284 sEntry += sDelim;
3285 xPropSet->getPropertyValue( PN_BINDING_EXPR ) >>= sTemp;
3286 sEntry += sTemp;
3287 m_pBindLB->InsertEntry( sEntry );
3289 if ( !m_xTempBinding.is() )
3290 m_xTempBinding = xPropSet;
3296 catch ( Exception& )
3298 SAL_WARN( "svx.form", "AddSubmissionDialog::FillAllBoxes(): exception caught" );
3302 // #i36342# we need a temporary binding; create one if no existing binding
3303 // is found
3304 if( !m_xTempBinding.is() )
3306 m_xCreatedBinding = m_xUIHelper->getBindingForNode(
3307 Reference<css::xml::dom::XNode>(
3308 xModel->getDefaultInstance()->getDocumentElement(),
3309 UNO_QUERY_THROW ),
3310 sal_True );
3311 m_xTempBinding = m_xCreatedBinding;
3314 // replace box
3315 m_pReplaceLB->InsertEntry( SVX_RESSTR( RID_STR_REPLACE_NONE ) );
3316 m_pReplaceLB->InsertEntry( SVX_RESSTR( RID_STR_REPLACE_INST ) );
3317 m_pReplaceLB->InsertEntry( SVX_RESSTR( RID_STR_REPLACE_DOC ) );
3320 // init the controls with the values of the submission
3321 if ( m_pItemNode && m_pItemNode->m_xPropSet.is() )
3323 m_xSubmission = m_pItemNode->m_xPropSet;
3324 OUString sTemp;
3327 m_xSubmission->getPropertyValue( PN_SUBMISSION_ID ) >>= sTemp;
3328 m_pNameED->SetText( sTemp );
3329 m_xSubmission->getPropertyValue( PN_SUBMISSION_ACTION ) >>= sTemp;
3330 m_pActionED->SetText( sTemp );
3331 m_xSubmission->getPropertyValue( PN_SUBMISSION_REF ) >>= sTemp;
3332 m_pRefED->SetText( sTemp );
3334 m_xSubmission->getPropertyValue( PN_SUBMISSION_METHOD ) >>= sTemp;
3335 sTemp = m_aMethodString.toUI( sTemp );
3336 sal_Int32 nPos = m_pMethodLB->GetEntryPos( sTemp );
3337 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
3338 nPos = m_pMethodLB->InsertEntry( sTemp );
3339 m_pMethodLB->SelectEntryPos( nPos );
3341 m_xSubmission->getPropertyValue( PN_SUBMISSION_BIND ) >>= sTemp;
3342 nPos = m_pBindLB->GetEntryPos( sTemp );
3343 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
3344 nPos = m_pBindLB->InsertEntry( sTemp );
3345 m_pBindLB->SelectEntryPos( nPos );
3347 m_xSubmission->getPropertyValue( PN_SUBMISSION_REPLACE ) >>= sTemp;
3348 sTemp = m_aReplaceString.toUI( sTemp );
3349 if ( sTemp.isEmpty() )
3350 sTemp = m_pReplaceLB->GetEntry(0); // first entry == "none"
3351 nPos = m_pReplaceLB->GetEntryPos( sTemp );
3352 if ( LISTBOX_ENTRY_NOTFOUND == nPos )
3353 nPos = m_pReplaceLB->InsertEntry( sTemp );
3354 m_pReplaceLB->SelectEntryPos( nPos );
3356 catch ( Exception& )
3358 SAL_WARN( "svx.form", "AddSubmissionDialog::FillAllBoxes(): exception caught" );
3362 m_pRefBtn->Enable( m_xTempBinding.is() );
3365 AddModelDialog::AddModelDialog(vcl::Window* pParent, bool bIsEdit)
3366 : ModalDialog(pParent, "AddModelDialog", "svx/ui/addmodeldialog.ui")
3368 get(m_pNameED, "name");
3369 get(m_pModifyCB, "modify");
3371 if (bIsEdit)
3372 SetText(get<FixedText>("alttitle")->GetText());
3375 AddModelDialog::~AddModelDialog()
3377 disposeOnce();
3380 void AddModelDialog::dispose()
3382 m_pNameED.clear();
3383 m_pModifyCB.clear();
3384 ModalDialog::dispose();
3387 AddInstanceDialog::AddInstanceDialog(vcl::Window* pParent, bool _bEdit)
3388 : ModalDialog(pParent, "AddInstanceDialog" , "svx/ui/addinstancedialog.ui")
3390 get(m_pNameED, "name");
3391 get(m_pURLFT, "urlft");
3392 get(m_pURLED, "url");
3393 get(m_pFilePickerBtn, "browse");
3394 get(m_pLinkInstanceCB, "link");
3396 if ( _bEdit )
3397 SetText(get<FixedText>("alttitle")->GetText());
3399 m_pURLED->DisableHistory();
3400 m_pFilePickerBtn->SetClickHdl( LINK( this, AddInstanceDialog, FilePickerHdl ) );
3402 // load the filter name from fps_office resource
3403 m_sAllFilterName = ResId(STR_FILTERNAME_ALL, *ResMgr::CreateResMgr("fps_office")).toString();
3406 AddInstanceDialog::~AddInstanceDialog()
3408 disposeOnce();
3411 void AddInstanceDialog::dispose()
3413 m_pNameED.clear();
3414 m_pURLFT.clear();
3415 m_pURLED.clear();
3416 m_pFilePickerBtn.clear();
3417 m_pLinkInstanceCB.clear();
3418 ModalDialog::dispose();
3421 IMPL_LINK_NOARG(AddInstanceDialog, FilePickerHdl)
3423 ::sfx2::FileDialogHelper aDlg(
3424 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
3425 INetURLObject aFile( SvtPathOptions().GetWorkPath() );
3427 aDlg.AddFilter( m_sAllFilterName, OUString(FILEDIALOG_FILTER_ALL) );
3428 OUString sFilterName( "XML" );
3429 aDlg.AddFilter( sFilterName, "*.xml" );
3430 aDlg.SetCurrentFilter( sFilterName );
3431 aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
3433 if( aDlg.Execute() == ERRCODE_NONE )
3434 m_pURLED->SetText( aDlg.GetPath() );
3436 return 0;
3439 LinkedInstanceWarningBox::LinkedInstanceWarningBox( vcl::Window* pParent )
3440 : MessageDialog(pParent, "FormLinkWarnDialog", "svx/ui/formlinkwarndialog.ui")
3446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */