1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/macros.h>
22 #include "datanavi.hxx"
23 #include "fmservs.hxx"
25 #include "datanavi.hrc"
26 #include "svx/fmresids.hrc"
28 #include <svx/svxids.hrc>
29 #include <tools/rcid.h>
30 #include <tools/diagnose_ex.h>
31 #include "svx/xmlexchg.hxx"
32 #include <svx/dialmgr.hxx>
33 #include <svx/fmshell.hxx>
34 #include <svtools/miscopt.hxx>
35 #include <unotools/pathoptions.hxx>
36 #include <unotools/viewoptions.hxx>
37 #include <svtools/svtools.hrc>
38 #include "svtools/treelistentry.hxx"
39 #include <sfx2/app.hxx>
40 #include <sfx2/filedlghelper.hxx>
41 #include <sfx2/objitem.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <sfx2/objsh.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <sfx2/dispatch.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>
59 #include <rtl/logfile.hxx>
61 using namespace ::com::sun::star::beans
;
62 using namespace ::com::sun::star::container
;
63 using namespace ::com::sun::star::datatransfer
;
64 using namespace ::com::sun::star::frame
;
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star::xml::dom::events
;
67 using namespace ::svx
;
69 #define CFGNAME_DATANAVIGATOR "DataNavigator"
70 #define CFGNAME_SHOWDETAILS "ShowDetails"
71 #define MSG_VARIABLE "%1"
72 #define MODELNAME "$MODELNAME"
73 #define INSTANCENAME "$INSTANCENAME"
74 #define ELEMENTNAME "$ELEMENTNAME"
75 #define ATTRIBUTENAME "$ATTRIBUTENAME"
76 #define SUBMISSIONNAME "$SUBMISSIONNAME"
77 #define BINDINGNAME "$BINDINGNAME"
79 //............................................................................
82 //............................................................................
84 // properties of instance
85 #define PN_INSTANCE_MODEL "Instance"
86 #define PN_INSTANCE_ID "ID"
87 #define PN_INSTANCE_URL "URL"
89 // properties of binding
90 #define PN_BINDING_ID "BindingID"
91 #define PN_BINDING_EXPR "BindingExpression"
92 #define PN_BINDING_MODEL "Model"
93 #define PN_BINDING_NAMESPACES "ModelNamespaces"
94 #define PN_READONLY_EXPR "ReadonlyExpression"
95 #define PN_RELEVANT_EXPR "RelevantExpression"
96 #define PN_REQUIRED_EXPR "RequiredExpression"
97 #define PN_CONSTRAINT_EXPR "ConstraintExpression"
98 #define PN_CALCULATE_EXPR "CalculateExpression"
99 #define PN_BINDING_TYPE "Type"
101 // properties of submission
102 #define PN_SUBMISSION_ID "ID"
103 #define PN_SUBMISSION_BIND "Bind"
104 #define PN_SUBMISSION_REF "Ref"
105 #define PN_SUBMISSION_ACTION "Action"
106 #define PN_SUBMISSION_METHOD "Method"
107 #define PN_SUBMISSION_REPLACE "Replace"
109 // other const strings
110 #define TRUE_VALUE "true()"
111 #define NEW_ELEMENT "newElement"
112 #define NEW_ATTRIBUTE "newAttribute"
113 #define EVENTTYPE_CHARDATA "DOMCharacterDataModified"
114 #define EVENTTYPE_ATTR "DOMAttrModified"
116 #define MIN_PAGE_COUNT 3 // at least one instance, one submission and one binding page
120 Reference
< css::xml::dom::XNode
> m_xNode
;
121 Reference
< XPropertySet
> m_xPropSet
;
123 ItemNode( const Reference
< css::xml::dom::XNode
>& _rxNode
) :
124 m_xNode( _rxNode
) {}
125 ItemNode( const Reference
< XPropertySet
>& _rxSet
) :
126 m_xPropSet( _rxSet
) {}
128 DataGroupType
GetDataGroupType() const;
131 //========================================================================
132 // class DataTreeListBox
133 //========================================================================
134 DataTreeListBox::DataTreeListBox( XFormsPage
* pPage
, DataGroupType _eGroup
, const ResId
& rResId
) :
136 SvTreeListBox( pPage
, rResId
),
138 m_pXFormsPage ( pPage
),
142 EnableContextMenuHandling();
144 if ( DGTInstance
== m_eGroup
)
145 SetDragDropMode( SV_DRAGDROP_CTRL_MOVE
|SV_DRAGDROP_CTRL_COPY
| SV_DRAGDROP_APP_COPY
);
148 DataTreeListBox::~DataTreeListBox()
153 sal_Int8
DataTreeListBox::AcceptDrop( const AcceptDropEvent
& /*rEvt*/ )
155 return DND_ACTION_NONE
;
157 sal_Int8
DataTreeListBox::ExecuteDrop( const ExecuteDropEvent
& /*rEvt*/ )
159 return DND_ACTION_NONE
;
161 void DataTreeListBox::StartDrag( sal_Int8
/*_nAction*/, const Point
& /*_rPosPixel*/ )
163 SvTreeListEntry
* pSelected
= FirstSelected();
165 // no drag without an entry
168 if ( m_eGroup
== DGTBinding
)
169 // for the moment, bindings cannot be dragged.
170 // #i59395# / 2005-12-15 / frank.schoenheit@sun.com
173 // GetServiceNameForNode() requires a datatype repository which
174 // will be automatically build if requested???
175 Reference
< css::xforms::XModel
> xModel( m_pXFormsPage
->GetXFormsHelper(), UNO_QUERY
);
176 Reference
< css::xforms::XDataTypeRepository
> xDataTypes
=
177 xModel
->getDataTypeRepository();
181 using namespace ::com::sun::star::uno
;
183 ItemNode
*pItemNode
= static_cast<ItemNode
*>(pSelected
->GetUserData());
187 // the only known (and allowed?) case where this happens are sub-entries of a submission
189 DBG_ASSERT( DGTSubmission
== m_eGroup
, "DataTreeListBox::StartDrag: how this?" );
190 pSelected
= GetParent( pSelected
);
191 DBG_ASSERT( pSelected
&& !GetParent( pSelected
), "DataTreeListBox::StartDrag: what kind of entry *is* this?" );
192 // on the submission page, we have only top-level entries (the submission themself)
193 // plus direct children of those (facets of a submission)
194 pItemNode
= pSelected
? static_cast< ItemNode
* >( pSelected
->GetUserData() ) : NULL
;
199 OXFormsDescriptor desc
;
200 desc
.szName
= GetEntryText(pSelected
);
201 if(pItemNode
->m_xNode
.is()) {
202 // a valid node interface tells us that we need to create a control from a binding
203 desc
.szServiceName
= m_pXFormsPage
->GetServiceNameForNode(pItemNode
->m_xNode
);
204 desc
.xPropSet
= m_pXFormsPage
->GetBindingForNode(pItemNode
->m_xNode
);
205 DBG_ASSERT( desc
.xPropSet
.is(), "DataTreeListBox::StartDrag(): invalid node binding" );
208 desc
.szServiceName
= FM_COMPONENT_COMMANDBUTTON
;
209 desc
.xPropSet
= pItemNode
->m_xPropSet
;
211 OXFormsTransferable
*pTransferable
= new OXFormsTransferable(desc
);
212 Reference
< XTransferable
> xEnsureDelete
= pTransferable
;
215 pTransferable
->StartDrag( this, DND_ACTION_COPY
);
219 PopupMenu
* DataTreeListBox::CreateContextMenu()
221 PopupMenu
* pMenu
= new PopupMenu( SVX_RES( RID_MENU_DATANAVIGATOR
) );
222 if ( DGTInstance
== m_eGroup
)
223 pMenu
->RemoveItem( pMenu
->GetItemPos( TBI_ITEM_ADD
) );
226 pMenu
->RemoveItem( pMenu
->GetItemPos( TBI_ITEM_ADD_ELEMENT
) );
227 pMenu
->RemoveItem( pMenu
->GetItemPos( TBI_ITEM_ADD_ATTRIBUTE
) );
229 if ( DGTSubmission
== m_eGroup
)
231 pMenu
->SetItemText( TBI_ITEM_ADD
, SVX_RESSTR( RID_STR_DATANAV_ADD_SUBMISSION
) );
232 pMenu
->SetItemText( TBI_ITEM_EDIT
, SVX_RESSTR( RID_STR_DATANAV_EDIT_SUBMISSION
) );
233 pMenu
->SetItemText( TBI_ITEM_REMOVE
, SVX_RESSTR( RID_STR_DATANAV_REMOVE_SUBMISSION
) );
237 pMenu
->SetItemText( TBI_ITEM_ADD
, SVX_RESSTR( RID_STR_DATANAV_ADD_BINDING
) );
238 pMenu
->SetItemText( TBI_ITEM_EDIT
, SVX_RESSTR( RID_STR_DATANAV_EDIT_BINDING
) );
239 pMenu
->SetItemText( TBI_ITEM_REMOVE
, SVX_RESSTR( RID_STR_DATANAV_REMOVE_BINDING
) );
242 m_pXFormsPage
->EnableMenuItems( pMenu
);
246 void DataTreeListBox::ExcecuteContextMenuAction( sal_uInt16 _nSelectedPopupEntry
)
248 m_pXFormsPage
->DoMenuAction( _nSelectedPopupEntry
);
251 void DataTreeListBox::RemoveEntry( SvTreeListEntry
* _pEntry
)
255 delete static_cast< ItemNode
* >( _pEntry
->GetUserData() );
256 SvTreeListBox::GetModel()->Remove( _pEntry
);
260 void DataTreeListBox::DeleteAndClear()
262 sal_uIntPtr i
, nCount
= GetEntryCount();
263 for ( i
= 0; i
< nCount
; ++i
)
265 SvTreeListEntry
* pEntry
= GetEntry(i
);
267 delete static_cast< ItemNode
* >( pEntry
->GetUserData() );
273 //========================================================================
275 //========================================================================
276 XFormsPage::XFormsPage( Window
* pParent
, DataNavigatorWindow
* _pNaviWin
, DataGroupType _eGroup
) :
278 TabPage( pParent
, SVX_RES( RID_SVX_XFORMS_TABPAGES
) ),
280 m_aToolBox ( this, SVX_RES( TB_ITEMS
) ),
281 m_aItemList ( this, _eGroup
, SVX_RES( LB_ITEMS
) ),
282 m_pNaviWin ( _pNaviWin
),
283 m_bHasModel ( false ),
284 m_eGroup ( _eGroup
),
285 m_TbxImageList ( SVX_RES( IL_TBX_BMPS
) ),
286 m_bLinkOnce ( false )
291 const ImageList
& rImageList
= m_TbxImageList
;
292 m_aToolBox
.SetItemImage( TBI_ITEM_ADD
, rImageList
.GetImage( IID_ITEM_ADD
) );
293 m_aToolBox
.SetItemImage( TBI_ITEM_ADD_ELEMENT
, rImageList
.GetImage( IID_ITEM_ADD_ELEMENT
) );
294 m_aToolBox
.SetItemImage( TBI_ITEM_ADD_ATTRIBUTE
, rImageList
.GetImage( IID_ITEM_ADD_ATTRIBUTE
) );
295 m_aToolBox
.SetItemImage( TBI_ITEM_EDIT
, rImageList
.GetImage( IID_ITEM_EDIT
) );
296 m_aToolBox
.SetItemImage( TBI_ITEM_REMOVE
, rImageList
.GetImage( IID_ITEM_REMOVE
) );
298 if ( DGTInstance
== m_eGroup
)
299 m_aToolBox
.RemoveItem( m_aToolBox
.GetItemPos( TBI_ITEM_ADD
) );
302 m_aToolBox
.RemoveItem( m_aToolBox
.GetItemPos( TBI_ITEM_ADD_ELEMENT
) );
303 m_aToolBox
.RemoveItem( m_aToolBox
.GetItemPos( TBI_ITEM_ADD_ATTRIBUTE
) );
305 if ( DGTSubmission
== m_eGroup
)
307 m_aToolBox
.SetItemText( TBI_ITEM_ADD
, SVX_RESSTR( RID_STR_DATANAV_ADD_SUBMISSION
) );
308 m_aToolBox
.SetItemText( TBI_ITEM_EDIT
, SVX_RESSTR( RID_STR_DATANAV_EDIT_SUBMISSION
) );
309 m_aToolBox
.SetItemText( TBI_ITEM_REMOVE
, SVX_RESSTR( RID_STR_DATANAV_REMOVE_SUBMISSION
) );
313 m_aToolBox
.SetItemText( TBI_ITEM_ADD
, SVX_RESSTR( RID_STR_DATANAV_ADD_BINDING
) );
314 m_aToolBox
.SetItemText( TBI_ITEM_EDIT
, SVX_RESSTR( RID_STR_DATANAV_EDIT_BINDING
) );
315 m_aToolBox
.SetItemText( TBI_ITEM_REMOVE
, SVX_RESSTR( RID_STR_DATANAV_REMOVE_BINDING
) );
319 const Size
aTbxSz( m_aToolBox
.CalcWindowSizePixel() );
320 m_aToolBox
.SetSizePixel( aTbxSz
);
321 m_aToolBox
.SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
322 m_aToolBox
.SetSelectHdl( LINK( this, XFormsPage
, TbxSelectHdl
) );
323 Point aPos
= m_aItemList
.GetPosPixel();
324 aPos
.Y() = aTbxSz
.Height();
325 m_aItemList
.SetPosPixel( aPos
);
327 m_aItemList
.SetSelectHdl( LINK( this, XFormsPage
, ItemSelectHdl
) );
328 m_aItemList
.SetNodeDefaultImages();
329 WinBits nBits
= WB_BORDER
| WB_TABSTOP
| WB_HIDESELECTION
| WB_NOINITIALSELECTION
;
330 if ( DGTInstance
== m_eGroup
|| DGTSubmission
== m_eGroup
)
331 nBits
|= WB_HASBUTTONS
| WB_HASLINES
| WB_HASLINESATROOT
| WB_HASBUTTONSATROOT
;
332 m_aItemList
.SetStyle( m_aItemList
.GetStyle() | nBits
);
334 ItemSelectHdl( &m_aItemList
);
336 //------------------------------------------------------------------------
337 XFormsPage::~XFormsPage()
340 //------------------------------------------------------------------------
341 IMPL_LINK_NOARG(XFormsPage
, TbxSelectHdl
)
343 DoToolBoxAction( m_aToolBox
.GetCurItemId() );
346 //------------------------------------------------------------------------
347 IMPL_LINK_NOARG(XFormsPage
, ItemSelectHdl
)
349 EnableMenuItems( NULL
);
352 //------------------------------------------------------------------------
353 void XFormsPage::AddChildren(
354 SvTreeListEntry
* _pParent
, const ImageList
& _rImgLst
,
355 const Reference
< css::xml::dom::XNode
>& _xNode
)
357 DBG_ASSERT( m_xUIHelper
.is(), "XFormsPage::AddChildren(): invalid UIHelper" );
361 Reference
< css::xml::dom::XNodeList
> xNodeList
= _xNode
->getChildNodes();
362 if ( xNodeList
.is() )
364 bool bShowDetails
= m_pNaviWin
->IsShowDetails();
365 sal_Int32 i
, nNodeCount
= xNodeList
->getLength();
366 for ( i
= 0; i
< nNodeCount
; ++i
)
368 Reference
< css::xml::dom::XNode
> xChild
= xNodeList
->item(i
);
369 css::xml::dom::NodeType eChildType
= xChild
->getNodeType();
370 Image aExpImg
, aCollImg
;
371 switch ( eChildType
)
373 case css::xml::dom::NodeType_ATTRIBUTE_NODE
:
374 aExpImg
= aCollImg
= _rImgLst
.GetImage( IID_ATTRIBUTE
);
376 case css::xml::dom::NodeType_ELEMENT_NODE
:
377 aExpImg
= aCollImg
= _rImgLst
.GetImage( IID_ELEMENT
);
379 case css::xml::dom::NodeType_TEXT_NODE
:
380 aExpImg
= aCollImg
= _rImgLst
.GetImage( IID_TEXT
);
383 aExpImg
= aCollImg
= _rImgLst
.GetImage( IID_OTHER
);
386 OUString sName
= m_xUIHelper
->getNodeDisplayName( xChild
, bShowDetails
);
387 if ( !sName
.isEmpty() )
389 ItemNode
* pNode
= new ItemNode( xChild
);
390 SvTreeListEntry
* pEntry
= m_aItemList
.InsertEntry(
391 sName
, aExpImg
, aCollImg
, _pParent
, sal_False
, LIST_APPEND
, pNode
);
392 if ( xChild
->hasAttributes() )
394 Reference
< css::xml::dom::XNamedNodeMap
> xMap
= xChild
->getAttributes();
397 aExpImg
= aCollImg
= _rImgLst
.GetImage( IID_ATTRIBUTE
);
398 sal_Int32 j
, nMapLen
= xMap
->getLength();
399 for ( j
= 0; j
< nMapLen
; ++j
)
401 Reference
< css::xml::dom::XNode
> xAttr
= xMap
->item(j
);
402 pNode
= new ItemNode( xAttr
);
404 m_xUIHelper
->getNodeDisplayName( xAttr
, bShowDetails
);
405 m_aItemList
.InsertEntry(
406 sAttrName
, aExpImg
, aCollImg
,
407 pEntry
, sal_False
, LIST_APPEND
, pNode
);
411 if ( xChild
->hasChildNodes() )
412 AddChildren( pEntry
, _rImgLst
, xChild
);
419 DBG_UNHANDLED_EXCEPTION();
422 //------------------------------------------------------------------------
423 bool XFormsPage::DoToolBoxAction( sal_uInt16 _nToolBoxID
) {
425 bool bHandled
= false;
426 bool bIsDocModified
= false;
427 m_pNaviWin
->DisableNotify( true );
429 switch ( _nToolBoxID
)
432 case TBI_ITEM_ADD_ELEMENT
:
433 case TBI_ITEM_ADD_ATTRIBUTE
:
436 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
437 DBG_ASSERT( xModel
.is(), "XFormsPage::DoToolBoxAction(): Action without model" );
438 if ( DGTSubmission
== m_eGroup
)
440 AddSubmissionDialog
aDlg( this, NULL
, m_xUIHelper
);
441 if ( aDlg
.Execute() == RET_OK
&& aDlg
.GetNewSubmission().is() )
445 Reference
< css::xforms::XSubmission
> xNewSubmission
= aDlg
.GetNewSubmission();
446 Reference
< XSet
> xSubmissions( xModel
->getSubmissions(), UNO_QUERY
);
447 xSubmissions
->insert( makeAny( xNewSubmission
) );
448 Reference
< XPropertySet
> xNewPropSet( xNewSubmission
, UNO_QUERY
);
449 SvTreeListEntry
* pEntry
= AddEntry( xNewPropSet
);
450 m_aItemList
.Select( pEntry
, sal_True
);
451 bIsDocModified
= true;
455 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while adding submission" );
461 DataItemType eType
= DITElement
;
462 SvTreeListEntry
* pEntry
= m_aItemList
.FirstSelected();
463 ItemNode
* pNode
= NULL
;
464 Reference
< css::xml::dom::XNode
> xParentNode
;
465 Reference
< XPropertySet
> xNewBinding
;
466 sal_uInt16 nResId
= 0;
467 bool bIsElement
= true;
468 if ( DGTInstance
== m_eGroup
)
470 if ( m_sInstanceURL
.Len() > 0 )
472 LinkedInstanceWarningBox
aMsgBox( this );
473 if ( aMsgBox
.Execute() != RET_OK
)
477 DBG_ASSERT( pEntry
, "XFormsPage::DoToolBoxAction(): no entry" );
478 ItemNode
* pParentNode
= static_cast< ItemNode
* >( pEntry
->GetUserData() );
479 DBG_ASSERT( pParentNode
, "XFormsPage::DoToolBoxAction(): no parent node" );
480 xParentNode
= pParentNode
->m_xNode
;
481 Reference
< css::xml::dom::XNode
> xNewNode
;
482 if ( TBI_ITEM_ADD_ELEMENT
== _nToolBoxID
)
486 nResId
= RID_STR_DATANAV_ADD_ELEMENT
;
487 xNewNode
= m_xUIHelper
->createElement( xParentNode
, NEW_ELEMENT
);
491 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create element" );
496 nResId
= RID_STR_DATANAV_ADD_ATTRIBUTE
;
498 eType
= DITAttribute
;
501 xNewNode
= m_xUIHelper
->createAttribute( xParentNode
, NEW_ATTRIBUTE
);
505 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while create attribute" );
511 xNewNode
= xParentNode
->appendChild( xNewNode
);
513 catch ( css::xml::dom::DOMException
& e
)
515 if ( e
.Code
== css::xml::dom::DOMExceptionType_DOMSTRING_SIZE_ERR
)
517 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): domexception: size error" );
519 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): domexception while append child" );
523 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while append child" );
528 Reference
< css::xml::dom::XNode
> xPNode
;
530 xPNode
= xNewNode
->getParentNode();
531 // attributes don't have parents in the DOM model
532 DBG_ASSERT( TBI_ITEM_ADD_ATTRIBUTE
== _nToolBoxID
533 || xPNode
.is(), "XFormsPage::DoToolboxAction(): node not added" );
537 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
542 m_xUIHelper
->getBindingForNode( xNewNode
, sal_True
);
546 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while get binding for node" );
548 pNode
= new ItemNode( xNewNode
);
554 nResId
= RID_STR_DATANAV_ADD_BINDING
;
555 xNewBinding
= xModel
->createBinding();
556 Reference
< XSet
> xBindings( xModel
->getBindings(), UNO_QUERY
);
557 xBindings
->insert( makeAny( xNewBinding
) );
558 pNode
= new ItemNode( xNewBinding
);
563 SAL_WARN( "svx.form", "XFormsPage::DoToolBoxAction(): exception while adding binding" );
567 AddDataItemDialog
aDlg( this, pNode
, m_xUIHelper
);
568 aDlg
.SetText( SVX_RESSTR( nResId
) );
569 aDlg
.InitText( eType
);
570 short nReturn
= aDlg
.Execute();
571 if ( DGTInstance
== m_eGroup
)
573 if ( RET_OK
== nReturn
)
575 SvTreeListEntry
* pNewEntry
= AddEntry( pNode
, bIsElement
);
576 m_aItemList
.MakeVisible( pNewEntry
);
577 m_aItemList
.Select( pNewEntry
, sal_True
);
578 bIsDocModified
= true;
584 Reference
< css::xml::dom::XNode
> xPNode
;
585 Reference
< css::xml::dom::XNode
> xNode
=
586 xParentNode
->removeChild( pNode
->m_xNode
);
588 xPNode
= xNode
->getParentNode();
589 DBG_ASSERT( !xPNode
.is(), "XFormsPage::RemoveEntry(): node not removed" );
594 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
600 if ( RET_OK
== nReturn
)
602 SvTreeListEntry
* pNewEntry
= AddEntry( xNewBinding
);
603 m_aItemList
.Select( pNewEntry
, sal_True
);
604 bIsDocModified
= true;
610 Reference
< XSet
> xBindings( xModel
->getBindings(), UNO_QUERY
);
611 xBindings
->remove( makeAny( xNewBinding
) );
615 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
627 SvTreeListEntry
* pEntry
= m_aItemList
.FirstSelected();
630 if ( DGTSubmission
== m_eGroup
&& m_aItemList
.GetParent( pEntry
) )
631 pEntry
= m_aItemList
.GetParent( pEntry
);
632 ItemNode
* pNode
= static_cast< ItemNode
* >( pEntry
->GetUserData() );
633 if ( DGTInstance
== m_eGroup
|| DGTBinding
== m_eGroup
)
635 if ( DGTInstance
== m_eGroup
&& m_sInstanceURL
.Len() > 0 )
637 LinkedInstanceWarningBox
aMsgBox( this );
638 if ( aMsgBox
.Execute() != RET_OK
)
642 AddDataItemDialog
aDlg( this, pNode
, m_xUIHelper
);
643 DataItemType eType
= DITElement
;
644 sal_uInt16 nResId
= RID_STR_DATANAV_EDIT_ELEMENT
;
645 if ( pNode
&& pNode
->m_xNode
.is() )
649 css::xml::dom::NodeType eChildType
= pNode
->m_xNode
->getNodeType();
650 if ( eChildType
== css::xml::dom::NodeType_ATTRIBUTE_NODE
)
652 nResId
= RID_STR_DATANAV_EDIT_ATTRIBUTE
;
653 eType
= DITAttribute
;
658 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
661 else if ( DGTBinding
== m_eGroup
)
663 nResId
= RID_STR_DATANAV_EDIT_BINDING
;
666 aDlg
.SetText( SVX_RESSTR( nResId
) );
667 aDlg
.InitText( eType
);
668 if ( aDlg
.Execute() == RET_OK
)
672 if ( DGTInstance
== m_eGroup
)
676 sNewName
= m_xUIHelper
->getNodeDisplayName(
677 pNode
->m_xNode
, m_pNaviWin
->IsShowDetails() );
681 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
688 String
sDelim( RTL_CONSTASCII_USTRINGPARAM( ": " ) );
690 pNode
->m_xPropSet
->getPropertyValue( PN_BINDING_ID
) >>= sTemp
;
691 sNewName
+= String( sTemp
);
693 pNode
->m_xPropSet
->getPropertyValue( PN_BINDING_EXPR
) >>= sTemp
;
694 sNewName
+= String( sTemp
);
698 SAL_WARN( "svx.form", "XFormsPage::DoToolboxAction(): exception caught" );
702 m_aItemList
.SetEntryText( pEntry
, sNewName
);
703 bIsDocModified
= true;
708 AddSubmissionDialog
aDlg( this, pNode
, m_xUIHelper
);
709 aDlg
.SetText( SVX_RESSTR( RID_STR_DATANAV_EDIT_SUBMISSION
) );
710 if ( aDlg
.Execute() == RET_OK
)
712 EditEntry( pNode
->m_xPropSet
);
713 bIsDocModified
= true;
720 case TBI_ITEM_REMOVE
:
723 if ( DGTInstance
== m_eGroup
&& m_sInstanceURL
.Len() > 0 )
725 LinkedInstanceWarningBox
aMsgBox( this );
726 if ( aMsgBox
.Execute() != RET_OK
)
729 bIsDocModified
= RemoveEntry();
733 case MID_INSERT_CONTROL
:
735 OSL_FAIL( "XFormsPage::DoToolboxAction: MID_INSERT_CONTROL not implemented, yet!" );
740 OSL_FAIL( "XFormsPage::DoToolboxAction: unknown ID!" );
744 m_pNaviWin
->DisableNotify( false );
745 EnableMenuItems( NULL
);
746 if ( bIsDocModified
)
747 m_pNaviWin
->SetDocModified();
751 //------------------------------------------------------------------------
752 SvTreeListEntry
* XFormsPage::AddEntry( ItemNode
* _pNewNode
, bool _bIsElement
)
754 SvTreeListEntry
* pParent
= m_aItemList
.FirstSelected();
755 const ImageList
& rImageList
= m_pNaviWin
->GetItemImageList();
756 sal_uInt16 nImageID
= ( _bIsElement
) ? IID_ELEMENT
: IID_ATTRIBUTE
;
757 Image aImage
= rImageList
.GetImage( nImageID
);
761 sName
= m_xUIHelper
->getNodeDisplayName(
762 _pNewNode
->m_xNode
, m_pNaviWin
->IsShowDetails() );
766 DBG_UNHANDLED_EXCEPTION();
768 return m_aItemList
.InsertEntry(
769 sName
, aImage
, aImage
, pParent
, sal_False
, LIST_APPEND
, _pNewNode
);
771 //------------------------------------------------------------------------
772 class lcl_ResourceString
779 lcl_ResourceString( const lcl_ResourceString
& );
781 virtual ~lcl_ResourceString()
785 // load UI resources from resource file
788 // create a resource manager, for the svx resource file
790 ResMgr
* pResMgr
= ResMgr::CreateResMgr(
791 "svx", Application::GetSettings().GetUILanguageTag() );
793 // load the resources for the AddSubmission modal dialog.
794 // This will create our own resource context.
795 ResId
aRes( RID_SVXDLG_ADD_SUBMISSION
, *pResMgr
);
796 aRes
.SetRT( RSC_MODALDIALOG
);
797 pResMgr
->GetResource( aRes
);
799 // now, we can access the local resources from the dialog's
801 _initResources(pResMgr
);
803 // clean up: remove context, and delete the resource manager
804 // ( Increment(..) is needed since PopContext() requires that
805 // the file pointer is at the end. )
806 pResMgr
->Increment( pResMgr
->GetRemainSize() );
807 pResMgr
->PopContext();
811 // load resources... to be overloaded in sub-classes
812 virtual void _initResources( ResMgr
* pMgr
) = 0;
815 class lcl_ReplaceString
: public lcl_ResourceString
818 OUString m_sInstance_UI
;
822 OUString m_sInstance_API
;
823 OUString m_sNone_API
;
825 lcl_ReplaceString() :
826 lcl_ResourceString(),
828 m_sInstance_API( "instance" ),
829 m_sNone_API( "none" )
834 lcl_ReplaceString( const lcl_ReplaceString
& );
836 virtual ~lcl_ReplaceString()
840 // load UI resources from resource file
841 virtual void _initResources( ResMgr
* pMgr
)
843 // now, we can access the local resources from the dialog's
845 m_sDoc_UI
= String( ResId( STR_REPLACE_DOC
, *pMgr
) );
846 m_sInstance_UI
= String( ResId( STR_REPLACE_INST
, *pMgr
) );
847 m_sNone_UI
= String( ResId( STR_REPLACE_NONE
, *pMgr
) );
852 /** create and obtain the singleton instance */
853 static const lcl_ReplaceString
& get()
855 // keep the singleton instance here
856 static lcl_ReplaceString
* m_pInstance
= NULL
;
858 if( m_pInstance
== NULL
)
859 m_pInstance
= new lcl_ReplaceString();
863 /** convert submission replace string from API value to UI value.
864 Use 'none' as default. */
865 OUString
toUI( const OUString
& rStr
) const
867 if( rStr
== m_sDoc_API
)
869 else if( rStr
== m_sInstance_API
)
870 return m_sInstance_UI
;
875 /** convert submission replace string from UI to API.
876 Use 'none' as default. */
877 OUString
toAPI( const OUString
& rStr
) const
879 if( rStr
== m_sDoc_UI
)
881 else if( rStr
== m_sInstance_UI
)
882 return m_sInstance_API
;
888 class lcl_MethodString
: public lcl_ResourceString
894 OUString m_sPost_API
;
899 lcl_ResourceString(),
900 m_sPost_API( "post" ),
907 lcl_MethodString( const lcl_MethodString
& );
909 virtual ~lcl_MethodString()
913 // load UI resources from resource file
914 virtual void _initResources(ResMgr
* pMgr
)
916 m_sPost_UI
= String( ResId( STR_METHOD_POST
, *pMgr
) );
917 m_sPut_UI
= String( ResId( STR_METHOD_PUT
, *pMgr
) );
918 m_sGet_UI
= String( ResId( STR_METHOD_GET
, *pMgr
) );
923 /** create and obtain the singleton instance */
924 static const lcl_MethodString
& get()
926 // keep the singleton instance here
927 static lcl_MethodString
* m_pInstance
= NULL
;
929 if( m_pInstance
== NULL
)
930 m_pInstance
= new lcl_MethodString();
934 /** convert from API to UI; put is default. */
935 OUString
toUI( const OUString
& rStr
) const
937 if( rStr
== m_sGet_API
)
939 else if( rStr
== m_sPost_API
)
945 /** convert from UI to API; put is default */
946 OUString
toAPI( const OUString
& rStr
) const
948 if( rStr
== m_sGet_UI
)
950 else if( rStr
== m_sPost_UI
)
957 //------------------------------------------------------------------------
958 SvTreeListEntry
* XFormsPage::AddEntry( const Reference
< XPropertySet
>& _rEntry
)
960 SvTreeListEntry
* pEntry
= NULL
;
961 const ImageList
& rImageList
= m_pNaviWin
->GetItemImageList();
962 Image aImage
= rImageList
.GetImage( IID_ELEMENT
);
964 ItemNode
* pNode
= new ItemNode( _rEntry
);
967 if ( DGTSubmission
== m_eGroup
)
972 _rEntry
->getPropertyValue( PN_SUBMISSION_ID
) >>= sTemp
;
973 pEntry
= m_aItemList
.InsertEntry( sTemp
, aImage
, aImage
, NULL
, sal_False
, LIST_APPEND
, pNode
);
975 _rEntry
->getPropertyValue( PN_SUBMISSION_ACTION
) >>= sTemp
;
976 String sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_ACTION
);
977 sEntry
+= String( sTemp
);
978 m_aItemList
.InsertEntry( sEntry
, aImage
, aImage
, pEntry
);
980 _rEntry
->getPropertyValue( PN_SUBMISSION_METHOD
) >>= sTemp
;
981 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_METHOD
);
982 sEntry
+= String( lcl_MethodString::get().toUI( sTemp
) );
983 m_aItemList
.InsertEntry( sEntry
, aImage
, aImage
, pEntry
);
985 _rEntry
->getPropertyValue( PN_SUBMISSION_REF
) >>= sTemp
;
986 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_REF
);
987 sEntry
+= String( sTemp
);
988 m_aItemList
.InsertEntry( sEntry
, aImage
, aImage
, pEntry
);
990 _rEntry
->getPropertyValue( PN_SUBMISSION_BIND
) >>= sTemp
;
991 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_BIND
);
992 sEntry
+= String( sTemp
);
993 m_aItemList
.InsertEntry( sEntry
, aImage
, aImage
, pEntry
);
995 _rEntry
->getPropertyValue( PN_SUBMISSION_REPLACE
) >>= sTemp
;
996 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_REPLACE
);
997 sEntry
+= String( lcl_ReplaceString::get().toUI( sTemp
) );
998 m_aItemList
.InsertEntry( sEntry
, aImage
, aImage
, pEntry
);
1000 catch ( Exception
& )
1002 SAL_WARN( "svx.form", "XFormsPage::AddEntry(Ref): exception caught" );
1005 else // then Binding Page
1009 String
sDelim( RTL_CONSTASCII_USTRINGPARAM( ": " ) );
1011 _rEntry
->getPropertyValue( PN_BINDING_ID
) >>= sTemp
;
1012 sName
+= String( sTemp
);
1014 _rEntry
->getPropertyValue( PN_BINDING_EXPR
) >>= sTemp
;
1015 sName
+= String( sTemp
);
1016 pEntry
= m_aItemList
.InsertEntry(
1017 sName
, aImage
, aImage
, NULL
, sal_False
, LIST_APPEND
, pNode
);
1019 catch ( Exception
& )
1021 SAL_WARN( "svx.form", "XFormsPage::AddEntry(Ref): exception caught" );
1028 //------------------------------------------------------------------------
1029 void XFormsPage::EditEntry( const Reference
< XPropertySet
>& _rEntry
)
1031 SvTreeListEntry
* pEntry
= NULL
;
1034 if ( DGTSubmission
== m_eGroup
)
1038 pEntry
= m_aItemList
.FirstSelected();
1040 // #i36262# may be called for submission entry *or* for
1041 // submission children. If we don't have any children, we
1042 // assume the latter case and use the parent
1043 if( m_aItemList
.GetEntry( pEntry
, 0 ) == NULL
)
1045 pEntry
= m_aItemList
.GetModel()->GetParent( pEntry
);
1048 _rEntry
->getPropertyValue( PN_SUBMISSION_ID
) >>= sTemp
;
1049 m_aItemList
.SetEntryText( pEntry
, sTemp
);
1051 _rEntry
->getPropertyValue( PN_SUBMISSION_BIND
) >>= sTemp
;
1052 String sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_BIND
);
1053 sEntry
+= String( sTemp
);
1054 sal_uIntPtr nPos
= 0;
1055 SvTreeListEntry
* pChild
= m_aItemList
.GetEntry( pEntry
, nPos
++ );
1056 m_aItemList
.SetEntryText( pChild
, sEntry
);
1057 _rEntry
->getPropertyValue( PN_SUBMISSION_REF
) >>= sTemp
;
1058 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_REF
);
1059 sEntry
+= String( sTemp
);
1060 pChild
= m_aItemList
.GetEntry( pEntry
, nPos
++ );
1061 m_aItemList
.SetEntryText( pChild
, sEntry
);
1062 _rEntry
->getPropertyValue( PN_SUBMISSION_ACTION
) >>= sTemp
;
1063 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_ACTION
);
1064 sEntry
+= String( sTemp
);
1065 pChild
= m_aItemList
.GetEntry( pEntry
, nPos
++ );
1066 m_aItemList
.SetEntryText( pChild
, sEntry
);
1067 _rEntry
->getPropertyValue( PN_SUBMISSION_METHOD
) >>= sTemp
;
1068 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_METHOD
);
1069 sEntry
+= String( lcl_MethodString::get().toUI( sTemp
) );
1070 pChild
= m_aItemList
.GetEntry( pEntry
, nPos
++ );
1071 m_aItemList
.SetEntryText( pChild
, sEntry
);
1072 _rEntry
->getPropertyValue( PN_SUBMISSION_REPLACE
) >>= sTemp
;
1073 sEntry
= SVX_RESSTR( RID_STR_DATANAV_SUBM_REPLACE
);
1074 sEntry
+= String( lcl_ReplaceString::get().toUI( sTemp
) );
1075 pChild
= m_aItemList
.GetEntry( pEntry
, nPos
++ );
1076 m_aItemList
.SetEntryText( pChild
, sEntry
);
1078 catch ( Exception
& )
1080 SAL_WARN( "svx.form", "XFormsPage::EditEntry(): exception caught" );
1085 //------------------------------------------------------------------------
1086 bool XFormsPage::RemoveEntry()
1089 SvTreeListEntry
* pEntry
= m_aItemList
.FirstSelected();
1091 ( DGTInstance
!= m_eGroup
|| m_aItemList
.GetParent( pEntry
) ) )
1093 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
1094 DBG_ASSERT( xModel
.is(), "XFormsPage::RemoveEntry(): no model" );
1095 ItemNode
* pNode
= static_cast< ItemNode
* >( pEntry
->GetUserData() );
1096 DBG_ASSERT( pNode
, "XFormsPage::RemoveEntry(): no node" );
1098 if ( DGTInstance
== m_eGroup
)
1102 DBG_ASSERT( pNode
->m_xNode
.is(), "XFormsPage::RemoveEntry(): no XNode" );
1103 css::xml::dom::NodeType eChildType
= pNode
->m_xNode
->getNodeType();
1104 bool bIsElement
= ( eChildType
== css::xml::dom::NodeType_ELEMENT_NODE
);
1105 sal_uInt16 nResId
= bIsElement
? RID_QRY_REMOVE_ELEMENT
: RID_QRY_REMOVE_ATTRIBUTE
;
1106 OUString sVar
= bIsElement
? OUString(ELEMENTNAME
) : OUString(ATTRIBUTENAME
);
1107 QueryBox
aQBox( this, SVX_RES( nResId
) );
1108 OUString sMessText
= aQBox
.GetMessText();
1109 sMessText
= sMessText
.replaceFirst(
1110 sVar
, m_xUIHelper
->getNodeDisplayName( pNode
->m_xNode
, sal_False
) );
1111 aQBox
.SetMessText( sMessText
);
1112 if ( aQBox
.Execute() == RET_YES
)
1114 SvTreeListEntry
* pParent
= m_aItemList
.GetParent( pEntry
);
1115 DBG_ASSERT( pParent
, "XFormsPage::RemoveEntry(): no parent entry" );
1116 ItemNode
* pParentNode
= static_cast< ItemNode
* >( pParent
->GetUserData() );
1117 DBG_ASSERT( pParentNode
&& pParentNode
->m_xNode
.is(), "XFormsPage::RemoveEntry(): no parent XNode" );
1119 Reference
< css::xml::dom::XNode
> xPNode
;
1120 Reference
< css::xml::dom::XNode
> xNode
=
1121 pParentNode
->m_xNode
->removeChild( pNode
->m_xNode
);
1123 xPNode
= xNode
->getParentNode();
1124 DBG_ASSERT( !xPNode
.is(), "XFormsPage::RemoveEntry(): node not removed" );
1128 catch ( Exception
& )
1130 SAL_WARN( "svx.form", "XFormsPage::RemoveEntry(): exception caught" );
1135 DBG_ASSERT( pNode
->m_xPropSet
.is(), "XFormsPage::RemoveEntry(): no propset" );
1136 bool bSubmission
= ( DGTSubmission
== m_eGroup
);
1137 sal_uInt16 nResId
= bSubmission
? RID_QRY_REMOVE_SUBMISSION
: RID_QRY_REMOVE_BINDING
;
1138 OUString sProperty
= bSubmission
? OUString(PN_SUBMISSION_ID
) : OUString(PN_BINDING_ID
);
1139 OUString sSearch
= bSubmission
? OUString(SUBMISSIONNAME
) : OUString(BINDINGNAME
);
1143 pNode
->m_xPropSet
->getPropertyValue( sProperty
) >>= sName
;
1145 catch ( Exception
& )
1147 SAL_WARN( "svx.form", "XFormsPage::RemoveEntry(): exception caught" );
1149 QueryBox
aQBox( this, SVX_RES( nResId
) );
1150 String sMessText
= aQBox
.GetMessText();
1151 sMessText
.SearchAndReplace( sSearch
, String( sName
) );
1152 aQBox
.SetMessText( sMessText
);
1153 if ( aQBox
.Execute() == RET_YES
)
1158 xModel
->getSubmissions()->remove( makeAny( pNode
->m_xPropSet
) );
1159 else // then Binding Page
1160 xModel
->getBindings()->remove( makeAny( pNode
->m_xPropSet
) );
1163 catch ( Exception
& )
1165 SAL_WARN( "svx.form", "XFormsPage::RemoveEntry(): exception caught" );
1171 m_aItemList
.RemoveEntry( pEntry
);
1177 //------------------------------------------------------------------------
1178 long XFormsPage::Notify( NotifyEvent
& rNEvt
)
1182 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
1184 sal_uInt16 nCode
= rNEvt
.GetKeyEvent()->GetKeyCode().GetCode();
1189 nHandled
= DoMenuAction( TBI_ITEM_REMOVE
);
1194 return nHandled
? nHandled
: Window::Notify( rNEvt
);
1196 //------------------------------------------------------------------------
1197 void XFormsPage::Resize()
1199 Size aSize
= GetOutputSizePixel();
1200 Size aTbxSize
= m_aToolBox
.GetSizePixel();
1201 aTbxSize
.Width() = aSize
.Width();
1202 m_aToolBox
.SetSizePixel( aTbxSize
);
1204 aSize
.Height() -= ( 4 + aTbxSize
.Height() );
1205 m_aItemList
.SetPosSizePixel( Point( 2, 2 + aTbxSize
.Height() ), aSize
);
1207 //------------------------------------------------------------------------
1208 String
XFormsPage::SetModel( const Reference
< css::xforms::XModel
>& _xModel
, sal_uInt16 _nPagePos
)
1210 DBG_ASSERT( _xModel
.is(), "XFormsPage::SetModel(): invalid model" );
1212 m_xUIHelper
= Reference
< css::xforms::XFormsUIHelper1
>( _xModel
, UNO_QUERY
);
1215 const ImageList
& rImageList
= m_pNaviWin
->GetItemImageList();
1221 DBG_ASSERT( _nPagePos
!= TAB_PAGE_NOTFOUND
, "XFormsPage::SetModel(): invalid page position" );
1224 Reference
< XContainer
> xContainer( _xModel
->getInstances(), UNO_QUERY
);
1225 if ( xContainer
.is() )
1226 m_pNaviWin
->AddContainerBroadcaster( xContainer
);
1228 Reference
< XEnumerationAccess
> xNumAccess( _xModel
->getInstances(), UNO_QUERY
);
1229 if ( xNumAccess
.is() )
1231 Reference
< XEnumeration
> xNum
= xNumAccess
->createEnumeration();
1232 if ( xNum
.is() && xNum
->hasMoreElements() )
1234 sal_uInt16 nIter
= 0;
1235 while ( xNum
->hasMoreElements() )
1237 if ( nIter
== _nPagePos
)
1239 Sequence
< PropertyValue
> xPropSeq
;
1240 Any aAny
= xNum
->nextElement();
1241 if ( aAny
>>= xPropSeq
)
1242 sRet
= LoadInstance( xPropSeq
, rImageList
);
1245 SAL_WARN( "svx.form", "XFormsPage::SetModel(): invalid instance" );
1251 xNum
->nextElement();
1260 SAL_WARN( "svx.form", "XFormsPage::SetModel(): exception caught" );
1265 case DGTSubmission
:
1267 DBG_ASSERT( TAB_PAGE_NOTFOUND
== _nPagePos
, "XFormsPage::SetModel(): invalid page position" );
1270 Reference
< XContainer
> xContainer( _xModel
->getSubmissions(), UNO_QUERY
);
1271 if ( xContainer
.is() )
1272 m_pNaviWin
->AddContainerBroadcaster( xContainer
);
1274 Reference
< XEnumerationAccess
> xNumAccess( _xModel
->getSubmissions(), UNO_QUERY
);
1275 if ( xNumAccess
.is() )
1277 Reference
< XEnumeration
> xNum
= xNumAccess
->createEnumeration();
1278 if ( xNum
.is() && xNum
->hasMoreElements() )
1280 while ( xNum
->hasMoreElements() )
1282 Reference
< XPropertySet
> xPropSet
;
1283 Any aAny
= xNum
->nextElement();
1284 if ( aAny
>>= xPropSet
)
1285 AddEntry( xPropSet
);
1292 SAL_WARN( "svx.form", "XFormsPage::SetModel(): exception caught" );
1299 DBG_ASSERT( TAB_PAGE_NOTFOUND
== _nPagePos
, "XFormsPage::SetModel(): invalid page position" );
1302 Reference
< XContainer
> xContainer( _xModel
->getBindings(), UNO_QUERY
);
1303 if ( xContainer
.is() )
1304 m_pNaviWin
->AddContainerBroadcaster( xContainer
);
1306 Reference
< XEnumerationAccess
> xNumAccess( _xModel
->getBindings(), UNO_QUERY
);
1307 if ( xNumAccess
.is() )
1309 Reference
< XEnumeration
> xNum
= xNumAccess
->createEnumeration();
1310 if ( xNum
.is() && xNum
->hasMoreElements() )
1312 Image aImage1
= rImageList
.GetImage( IID_ELEMENT
);
1313 Image aImage2
= rImageList
.GetImage( IID_ELEMENT
);
1314 String
sDelim( RTL_CONSTASCII_USTRINGPARAM( ": " ) );
1315 while ( xNum
->hasMoreElements() )
1317 Reference
< XPropertySet
> xPropSet
;
1318 Any aAny
= xNum
->nextElement();
1319 if ( aAny
>>= xPropSet
)
1323 xPropSet
->getPropertyValue( PN_BINDING_ID
) >>= sTemp
;
1324 sEntry
+= String( sTemp
);
1326 xPropSet
->getPropertyValue( PN_BINDING_EXPR
) >>= sTemp
;
1327 sEntry
+= String( sTemp
);
1329 ItemNode
* pNode
= new ItemNode( xPropSet
);
1330 m_aItemList
.InsertEntry(
1331 sEntry
, aImage1
, aImage2
, NULL
, sal_False
, LIST_APPEND
, pNode
);
1339 SAL_WARN( "svx.form", "XFormsPage::SetModel(): exception caught" );
1344 OSL_FAIL( "XFormsPage::SetModel: unknown group!" );
1348 EnableMenuItems( NULL
);
1352 //------------------------------------------------------------------------
1353 void XFormsPage::ClearModel()
1355 m_bHasModel
= false;
1356 m_aItemList
.DeleteAndClear();
1358 //------------------------------------------------------------------------
1359 String
XFormsPage::LoadInstance(
1360 const Sequence
< PropertyValue
>& _xPropSeq
, const ImageList
& _rImgLst
)
1364 OUString sInstModel
= PN_INSTANCE_MODEL
;
1365 OUString sInstName
= PN_INSTANCE_ID
;
1366 OUString sInstURL
= PN_INSTANCE_URL
;
1367 const PropertyValue
* pProps
= _xPropSeq
.getConstArray();
1368 const PropertyValue
* pPropsEnd
= pProps
+ _xPropSeq
.getLength();
1369 for ( ; pProps
!= pPropsEnd
; ++pProps
)
1371 if ( sInstModel
== pProps
->Name
)
1373 Reference
< css::xml::dom::XNode
> xRoot
;
1374 if ( pProps
->Value
>>= xRoot
)
1378 Reference
< XEventTarget
> xTarget( xRoot
, UNO_QUERY
);
1380 m_pNaviWin
->AddEventBroadcaster( xTarget
);
1382 #if OSL_DEBUG_LEVEL > 0
1383 css::xml::dom::NodeType eNodeType
= xRoot
->getNodeType(); (void)eNodeType
;
1385 OUString sNodeName
=
1386 m_xUIHelper
->getNodeDisplayName( xRoot
, m_pNaviWin
->IsShowDetails() );
1387 if ( sNodeName
.isEmpty() )
1388 sNodeName
= xRoot
->getNodeName();
1389 if ( xRoot
->hasChildNodes() )
1390 AddChildren( NULL
, _rImgLst
, xRoot
);
1392 catch ( Exception
& )
1394 SAL_WARN( "svx.form", "XFormsPage::LoadInstance(): exception caught" );
1398 else if ( sInstName
== pProps
->Name
&& ( pProps
->Value
>>= sTemp
) )
1399 m_sInstanceName
= sRet
= sTemp
;
1400 else if ( sInstURL
== pProps
->Name
&& ( pProps
->Value
>>= sTemp
) )
1401 m_sInstanceURL
= sTemp
;
1407 //------------------------------------------------------------------------
1408 bool XFormsPage::DoMenuAction( sal_uInt16 _nMenuID
)
1410 return DoToolBoxAction( _nMenuID
);
1413 //------------------------------------------------------------------------
1414 void XFormsPage::EnableMenuItems( Menu
* _pMenu
)
1416 sal_Bool bEnableAdd
= sal_False
;
1417 sal_Bool bEnableEdit
= sal_False
;
1418 sal_Bool bEnableRemove
= sal_False
;
1420 SvTreeListEntry
* pEntry
= m_aItemList
.FirstSelected();
1423 bEnableAdd
= sal_True
;
1424 bool bSubmitChild
= false;
1425 if ( DGTSubmission
== m_eGroup
&& m_aItemList
.GetParent( pEntry
) )
1427 pEntry
= m_aItemList
.GetParent( pEntry
);
1428 bSubmitChild
= true;
1430 ItemNode
* pNode
= static_cast< ItemNode
* >( pEntry
->GetUserData() );
1431 if ( pNode
&& ( pNode
->m_xNode
.is() || pNode
->m_xPropSet
.is() ) )
1433 bEnableEdit
= sal_True
;
1434 bEnableRemove
= ( bSubmitChild
!= true );
1435 if ( DGTInstance
== m_eGroup
&& !m_aItemList
.GetParent( pEntry
) )
1436 bEnableRemove
= sal_False
;
1437 if ( pNode
->m_xNode
.is() )
1441 css::xml::dom::NodeType eChildType
= pNode
->m_xNode
->getNodeType();
1442 if ( eChildType
!= css::xml::dom::NodeType_ELEMENT_NODE
1443 && eChildType
!= css::xml::dom::NodeType_DOCUMENT_NODE
)
1445 bEnableAdd
= sal_False
;
1448 catch ( Exception
& )
1450 SAL_WARN( "svx.form", "XFormsPage::EnableMenuItems(): exception caught" );
1455 else if ( m_eGroup
!= DGTInstance
)
1456 bEnableAdd
= sal_True
;
1458 m_aToolBox
.EnableItem( TBI_ITEM_ADD
, bEnableAdd
);
1459 m_aToolBox
.EnableItem( TBI_ITEM_ADD_ELEMENT
, bEnableAdd
);
1460 m_aToolBox
.EnableItem( TBI_ITEM_ADD_ATTRIBUTE
, bEnableAdd
);
1461 m_aToolBox
.EnableItem( TBI_ITEM_EDIT
, bEnableEdit
);
1462 m_aToolBox
.EnableItem( TBI_ITEM_REMOVE
, bEnableRemove
);
1466 _pMenu
->EnableItem( TBI_ITEM_ADD
, bEnableAdd
);
1467 _pMenu
->EnableItem( TBI_ITEM_ADD_ELEMENT
, bEnableAdd
);
1468 _pMenu
->EnableItem( TBI_ITEM_ADD_ATTRIBUTE
, bEnableAdd
);
1469 _pMenu
->EnableItem( TBI_ITEM_EDIT
, bEnableEdit
);
1470 _pMenu
->EnableItem( TBI_ITEM_REMOVE
, bEnableRemove
);
1472 if ( DGTInstance
== m_eGroup
)
1474 sal_uInt16 nResId1
= RID_STR_DATANAV_EDIT_ELEMENT
;
1475 sal_uInt16 nResId2
= RID_STR_DATANAV_REMOVE_ELEMENT
;
1478 ItemNode
* pNode
= static_cast< ItemNode
* >( pEntry
->GetUserData() );
1479 if ( pNode
&& pNode
->m_xNode
.is() )
1483 css::xml::dom::NodeType eChildType
= pNode
->m_xNode
->getNodeType();
1484 if ( eChildType
== css::xml::dom::NodeType_ATTRIBUTE_NODE
)
1486 nResId1
= RID_STR_DATANAV_EDIT_ATTRIBUTE
;
1487 nResId2
= RID_STR_DATANAV_REMOVE_ATTRIBUTE
;
1490 catch ( Exception
& )
1492 SAL_WARN( "svx.form", "XFormsPage::EnableMenuItems(): exception caught" );
1496 m_aToolBox
.SetItemText( TBI_ITEM_EDIT
, SVX_RESSTR( nResId1
) );
1497 m_aToolBox
.SetItemText( TBI_ITEM_REMOVE
, SVX_RESSTR( nResId2
) );
1500 _pMenu
->SetItemText( TBI_ITEM_EDIT
, SVX_RESSTR( nResId1
) );
1501 _pMenu
->SetItemText( TBI_ITEM_REMOVE
, SVX_RESSTR( nResId2
) );
1507 //========================================================================
1508 // class DataNavigatorWindow
1509 //========================================================================
1510 DataNavigatorWindow::DataNavigatorWindow( Window
* pParent
, SfxBindings
* pBindings
) :
1512 Window( pParent
, SVX_RES( RID_SVXWIN_DATANAVIGATOR
) ),
1514 m_aModelsBox ( this, SVX_RES( LB_MODELS
) ),
1515 m_aModelBtn ( this, SVX_RES( MB_MODELS
) ),
1516 m_aTabCtrl ( this, SVX_RES( TC_ITEMS
) ),
1517 m_aInstanceBtn ( this, SVX_RES( MB_INSTANCES
) ),
1519 m_pInstPage ( NULL
),
1520 m_pSubmissionPage ( NULL
),
1521 m_pBindingPage ( NULL
),
1525 m_nBorderHeight ( 0 ),
1526 m_nLastSelectedPos ( LISTBOX_ENTRY_NOTFOUND
),
1527 m_bShowDetails ( false ),
1528 m_bIsNotifyDisabled ( false ),
1530 m_aItemImageList ( SVX_RES( IL_ITEM_BMPS
) ),
1531 m_xDataListener ( new DataListener( this ) )
1536 // init minimal metric
1537 m_a2Size
= LogicToPixel( Size( 2, 2 ), MAP_APPFONT
);
1538 m_a3Size
= LogicToPixel( Size( 3, 3 ), MAP_APPFONT
);
1539 Size aOutSz
= GetOutputSizePixel();
1540 Size aLogSize
= PixelToLogic( aOutSz
, MAP_APPFONT
);
1541 m_nMinWidth
= aLogSize
.Width();
1542 m_nMinHeight
= aLogSize
.Height();
1543 m_nBorderHeight
= 4*m_a3Size
.Height() +
1544 m_aModelBtn
.GetSizePixel().Height() + m_aInstanceBtn
.GetSizePixel().Height();
1547 m_aModelsBox
.SetSelectHdl( LINK( this, DataNavigatorWindow
, ModelSelectHdl
) );
1548 Link aLink
= LINK( this, DataNavigatorWindow
, MenuSelectHdl
);
1549 m_aModelBtn
.SetSelectHdl( aLink
);
1550 m_aInstanceBtn
.SetSelectHdl( aLink
);
1551 aLink
= LINK( this, DataNavigatorWindow
, MenuActivateHdl
);
1552 m_aModelBtn
.SetActivateHdl( aLink
);
1553 m_aInstanceBtn
.SetActivateHdl( aLink
);
1554 m_aTabCtrl
.SetActivatePageHdl( LINK( this, DataNavigatorWindow
, ActivatePageHdl
) );
1555 m_aUpdateTimer
.SetTimeout( 2000 );
1556 m_aUpdateTimer
.SetTimeoutHdl( LINK( this, DataNavigatorWindow
, UpdateHdl
) );
1560 sal_Int32 nPageId
= TID_INSTANCE
;
1561 SvtViewOptions
aViewOpt( E_TABDIALOG
, CFGNAME_DATANAVIGATOR
);
1562 if ( aViewOpt
.Exists() )
1564 nPageId
= aViewOpt
.GetPageID();
1565 aViewOpt
.GetUserItem(CFGNAME_SHOWDETAILS
) >>= m_bShowDetails
;
1568 Menu
* pMenu
= m_aInstanceBtn
.GetPopupMenu();
1569 pMenu
->SetItemBits( MID_SHOW_DETAILS
, MIB_CHECKABLE
);
1570 pMenu
->CheckItem( MID_SHOW_DETAILS
, m_bShowDetails
);
1572 m_aTabCtrl
.SetCurPageId( static_cast< sal_uInt16
>( nPageId
) );
1573 ActivatePageHdl( &m_aTabCtrl
);
1576 DBG_ASSERT( pBindings
!= NULL
,
1577 "DataNavigatorWindow::LoadModels(): no SfxBindings; can't get frame" );
1578 m_xFrame
= Reference
<XFrame
>(
1579 pBindings
->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(),
1581 DBG_ASSERT( m_xFrame
.is(), "DataNavigatorWindow::LoadModels(): no frame" );
1582 // add frameaction listener
1583 Reference
< XFrameActionListener
> xListener(
1584 static_cast< XFrameActionListener
* >( m_xDataListener
.get() ), UNO_QUERY
);
1585 m_xFrame
->addFrameActionListener( xListener
);
1587 // load xforms models of the current document
1590 //------------------------------------------------------------------------
1591 DataNavigatorWindow::~DataNavigatorWindow()
1593 SvtViewOptions
aViewOpt( E_TABDIALOG
, CFGNAME_DATANAVIGATOR
);
1594 aViewOpt
.SetPageID( static_cast< sal_Int32
>( m_aTabCtrl
.GetCurPageId() ) );
1596 aAny
<<= m_bShowDetails
;
1597 aViewOpt
.SetUserItem(CFGNAME_SHOWDETAILS
,aAny
);
1600 delete m_pSubmissionPage
;
1601 delete m_pBindingPage
;
1603 sal_Int32 i
, nCount
= m_aPageList
.size();
1604 for ( i
= 0; i
< nCount
; ++i
)
1605 delete m_aPageList
[i
];
1606 Reference
< XFrameActionListener
> xListener(
1607 static_cast< XFrameActionListener
* >( m_xDataListener
.get() ), UNO_QUERY
);
1608 m_xFrame
->removeFrameActionListener( xListener
);
1609 RemoveBroadcaster();
1610 m_xDataListener
.clear();
1613 // -----------------------------------------------------------------------
1614 IMPL_LINK( DataNavigatorWindow
, ModelSelectHdl
, ListBox
*, pBox
)
1616 sal_uInt16 nPos
= m_aModelsBox
.GetSelectEntryPos();
1617 // pBox == NULL, if you want to force a new fill.
1618 if ( nPos
!= m_nLastSelectedPos
|| !pBox
)
1620 m_nLastSelectedPos
= nPos
;
1621 ClearAllPageModels( pBox
!= NULL
);
1628 // -----------------------------------------------------------------------
1629 IMPL_LINK( DataNavigatorWindow
, MenuSelectHdl
, MenuButton
*, pBtn
)
1631 bool bIsDocModified
= false;
1632 Reference
< css::xforms::XFormsUIHelper1
> xUIHelper
;
1633 sal_uInt16 nSelectedPos
= m_aModelsBox
.GetSelectEntryPos();
1634 OUString
sSelectedModel( m_aModelsBox
.GetEntry( nSelectedPos
) );
1635 Reference
< css::xforms::XModel
> xModel
;
1638 Any aAny
= m_xDataContainer
->getByName( sSelectedModel
);
1639 if ( aAny
>>= xModel
)
1640 xUIHelper
= Reference
< css::xforms::XFormsUIHelper1
>( xModel
, UNO_QUERY
);
1642 catch ( Exception
& )
1644 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1646 DBG_ASSERT( xUIHelper
.is(), "DataNavigatorWindow::MenuSelectHdl(): no UIHelper" );
1648 m_bIsNotifyDisabled
= true;
1650 if ( &m_aModelBtn
== pBtn
)
1652 switch ( pBtn
->GetCurItemId() )
1654 case MID_MODELS_ADD
:
1656 AddModelDialog
aDlg( this, false );
1657 bool bShowDialog
= true;
1658 while ( bShowDialog
)
1660 bShowDialog
= false;
1661 if ( aDlg
.Execute() == RET_OK
)
1663 String sNewName
= aDlg
.GetName();
1664 sal_Bool bDocumentData
= aDlg
.GetModifyDoc();
1666 if ( m_aModelsBox
.GetEntryPos( sNewName
) != LISTBOX_ENTRY_NOTFOUND
)
1668 // error: model name already exists
1669 ErrorBox
aErrBox( this, SVX_RES( RID_ERR_DOUBLE_MODELNAME
) );
1670 OUString sMessText
= aErrBox
.GetMessText();
1671 sMessText
= sMessText
.replaceFirst( MSG_VARIABLE
, sNewName
);
1672 aErrBox
.SetMessText( sMessText
);
1680 // add new model to frame model
1681 Reference
< css::xforms::XModel
> xNewModel(
1682 xUIHelper
->newModel( m_xFrameModel
, sNewName
), UNO_SET_THROW
);
1684 Reference
< XPropertySet
> xModelProps( xNewModel
, UNO_QUERY_THROW
);
1685 xModelProps
->setPropertyValue(
1686 OUString( "ExternalData" ),
1687 makeAny( sal_Bool( !bDocumentData
) ) );
1689 sal_uInt16 nNewPos
= m_aModelsBox
.InsertEntry( sNewName
);
1690 m_aModelsBox
.SelectEntryPos( nNewPos
);
1691 ModelSelectHdl( &m_aModelsBox
);
1692 bIsDocModified
= true;
1694 catch ( Exception
& )
1696 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1703 case MID_MODELS_EDIT
:
1705 AddModelDialog
aDlg( this, true );
1706 aDlg
.SetName( sSelectedModel
);
1708 bool bDocumentData( false );
1711 Reference
< css::xforms::XFormsSupplier
> xFormsSupp( m_xFrameModel
, UNO_QUERY_THROW
);
1712 Reference
< XNameContainer
> xXForms( xFormsSupp
->getXForms(), UNO_SET_THROW
);
1713 Reference
< XPropertySet
> xModelProps( xXForms
->getByName( sSelectedModel
), UNO_QUERY_THROW
);
1714 sal_Bool bExternalData
= sal_False
;
1715 OSL_VERIFY( xModelProps
->getPropertyValue(
1716 OUString( "ExternalData" ) ) >>= bExternalData
);
1717 bDocumentData
= ( bExternalData
== sal_False
);
1719 catch( const Exception
& )
1721 DBG_UNHANDLED_EXCEPTION();
1723 aDlg
.SetModifyDoc( bDocumentData
);
1725 if ( aDlg
.Execute() == RET_OK
)
1727 if ( aDlg
.GetModifyDoc() != bool( bDocumentData
) )
1729 bDocumentData
= aDlg
.GetModifyDoc();
1732 Reference
< css::xforms::XFormsSupplier
> xFormsSupp( m_xFrameModel
, UNO_QUERY_THROW
);
1733 Reference
< XNameContainer
> xXForms( xFormsSupp
->getXForms(), UNO_SET_THROW
);
1734 Reference
< XPropertySet
> xModelProps( xXForms
->getByName( sSelectedModel
), UNO_QUERY_THROW
);
1735 xModelProps
->setPropertyValue(
1736 OUString( "ExternalData" ),
1737 makeAny( sal_Bool( !bDocumentData
) ) );
1738 bIsDocModified
= true;
1740 catch( const Exception
& )
1742 DBG_UNHANDLED_EXCEPTION();
1746 String sNewName
= aDlg
.GetName();
1747 if ( sNewName
.Len() > 0 && ( sNewName
!= String( sSelectedModel
) ) )
1751 xUIHelper
->renameModel( m_xFrameModel
, sSelectedModel
, sNewName
);
1753 m_aModelsBox
.RemoveEntry( nSelectedPos
);
1754 nSelectedPos
= m_aModelsBox
.InsertEntry( sNewName
);
1755 m_aModelsBox
.SelectEntryPos( nSelectedPos
);
1756 bIsDocModified
= true;
1758 catch ( Exception
& )
1760 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1766 case MID_MODELS_REMOVE
:
1768 QueryBox
aQBox( this, SVX_RES( RID_QRY_REMOVE_MODEL
) );
1769 OUString sText
= aQBox
.GetMessText();
1770 sText
= sText
.replaceFirst( MODELNAME
, sSelectedModel
);
1771 aQBox
.SetMessText( sText
);
1772 if ( aQBox
.Execute() == RET_YES
)
1776 xUIHelper
->removeModel( m_xFrameModel
, sSelectedModel
);
1778 catch ( Exception
& )
1780 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1782 m_aModelsBox
.RemoveEntry( nSelectedPos
);
1783 if ( m_aModelsBox
.GetEntryCount() <= nSelectedPos
)
1784 nSelectedPos
= m_aModelsBox
.GetEntryCount() - 1;
1785 m_aModelsBox
.SelectEntryPos( nSelectedPos
);
1786 ModelSelectHdl( &m_aModelsBox
);
1787 bIsDocModified
= true;
1793 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong menu item" );
1797 else if ( &m_aInstanceBtn
== pBtn
)
1799 switch ( pBtn
->GetCurItemId() )
1801 case MID_INSTANCES_ADD
:
1803 AddInstanceDialog
aDlg( this, false );
1804 if ( aDlg
.Execute() == RET_OK
)
1806 sal_uInt16 nInst
= GetNewPageId();
1807 OUString sName
= aDlg
.GetName();
1808 OUString sURL
= aDlg
.GetURL();
1809 bool bLinkOnce
= aDlg
.IsLinkInstance();
1812 Reference
< css::xml::dom::XDocument
> xNewInst
=
1813 xUIHelper
->newInstance( sName
, sURL
, !bLinkOnce
);
1815 catch ( Exception
& )
1817 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1819 ModelSelectHdl( NULL
);
1820 m_aTabCtrl
.SetCurPageId( nInst
);
1821 XFormsPage
* pPage
= GetCurrentPage( nInst
);
1822 pPage
->SetInstanceName(sName
);
1823 pPage
->SetInstanceURL(sURL
);
1824 pPage
->SetLinkOnce(bLinkOnce
);
1825 ActivatePageHdl( &m_aTabCtrl
);
1826 bIsDocModified
= true;
1830 case MID_INSTANCES_EDIT
:
1833 XFormsPage
* pPage
= GetCurrentPage( nId
);
1836 AddInstanceDialog
aDlg( this, true );
1837 aDlg
.SetName( pPage
->GetInstanceName() );
1838 aDlg
.SetURL( pPage
->GetInstanceURL() );
1839 aDlg
.SetLinkInstance( pPage
->GetLinkOnce() );
1840 String sOldName
= aDlg
.GetName();
1841 if ( aDlg
.Execute() == RET_OK
)
1843 String sNewName
= aDlg
.GetName();
1844 OUString sURL
= aDlg
.GetURL();
1845 bool bLinkOnce
= aDlg
.IsLinkInstance();
1848 xUIHelper
->renameInstance( sOldName
,
1853 catch ( Exception
& )
1855 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1857 pPage
->SetInstanceName(sNewName
);
1858 pPage
->SetInstanceURL(sURL
);
1859 pPage
->SetLinkOnce(bLinkOnce
);
1860 m_aTabCtrl
.SetPageText( nId
, sNewName
);
1861 bIsDocModified
= true;
1866 case MID_INSTANCES_REMOVE
:
1869 XFormsPage
* pPage
= GetCurrentPage( nId
);
1872 String sInstName
= pPage
->GetInstanceName();
1873 QueryBox
aQBox( this, SVX_RES( RID_QRY_REMOVE_INSTANCE
) );
1874 OUString sMessText
= aQBox
.GetMessText();
1875 sMessText
= sMessText
.replaceFirst( INSTANCENAME
, sInstName
);
1876 aQBox
.SetMessText( sMessText
);
1877 if ( aQBox
.Execute() == RET_YES
)
1879 bool bDoRemove
= false;
1880 if ( nId
> TID_INSTANCE
)
1882 PageList::iterator aPageListEnd
= m_aPageList
.end();
1883 PageList::iterator aFoundPage
=
1884 std::find( m_aPageList
.begin(), aPageListEnd
, pPage
);
1885 if ( aFoundPage
!= aPageListEnd
)
1887 m_aPageList
.erase( aFoundPage
);
1894 DELETEZ( m_pInstPage
);
1902 xUIHelper
->removeInstance( sInstName
);
1904 catch ( Exception
& )
1906 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): exception caught" );
1908 m_aTabCtrl
.RemovePage( nId
);
1909 m_aTabCtrl
.SetCurPageId( TID_INSTANCE
);
1910 ModelSelectHdl( NULL
);
1911 bIsDocModified
= true;
1917 case MID_SHOW_DETAILS
:
1919 m_bShowDetails
= !m_bShowDetails
;
1920 m_aInstanceBtn
.GetPopupMenu()->CheckItem( MID_SHOW_DETAILS
, m_bShowDetails
);
1921 ModelSelectHdl( &m_aModelsBox
);
1926 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong menu item" );
1932 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuSelectHdl(): wrong button" );
1935 m_bIsNotifyDisabled
= false;
1937 if ( bIsDocModified
)
1941 // -----------------------------------------------------------------------
1942 IMPL_LINK( DataNavigatorWindow
, MenuActivateHdl
, MenuButton
*, pBtn
)
1944 Menu
* pMenu
= pBtn
->GetPopupMenu();
1946 if ( &m_aInstanceBtn
== pBtn
)
1948 bool bIsInstPage
= ( m_aTabCtrl
.GetCurPageId() >= TID_INSTANCE
);
1949 pMenu
->EnableItem( MID_INSTANCES_EDIT
, bIsInstPage
);
1950 pMenu
->EnableItem( MID_INSTANCES_REMOVE
,
1951 bIsInstPage
&& m_aTabCtrl
.GetPageCount() > MIN_PAGE_COUNT
);
1952 pMenu
->EnableItem( MID_SHOW_DETAILS
, bIsInstPage
);
1954 else if ( &m_aModelBtn
== pBtn
)
1956 // we need at least one model!
1957 pMenu
->EnableItem( MID_MODELS_REMOVE
, m_aModelsBox
.GetEntryCount() > 1 );
1961 SAL_WARN( "svx.form", "DataNavigatorWindow::MenuActivateHdl(): wrong button" );
1965 // -----------------------------------------------------------------------
1966 IMPL_LINK_NOARG(DataNavigatorWindow
, ActivatePageHdl
)
1969 XFormsPage
* pPage
= GetCurrentPage( nId
);
1972 m_aTabCtrl
.SetTabPage( nId
, pPage
);
1973 if ( m_xDataContainer
.is() && !pPage
->HasModel() )
1979 // -----------------------------------------------------------------------
1980 IMPL_LINK_NOARG(DataNavigatorWindow
, UpdateHdl
)
1982 ModelSelectHdl( NULL
);
1985 // -----------------------------------------------------------------------
1986 XFormsPage
* DataNavigatorWindow::GetCurrentPage( sal_uInt16
& rCurId
)
1988 rCurId
= m_aTabCtrl
.GetCurPageId();
1989 XFormsPage
* pPage
= NULL
;
1992 case TID_SUBMISSION
:
1994 if ( !m_pSubmissionPage
)
1995 m_pSubmissionPage
= new XFormsPage( &m_aTabCtrl
, this, DGTSubmission
);
1996 pPage
= m_pSubmissionPage
;
2002 if ( !m_pBindingPage
)
2003 m_pBindingPage
= new XFormsPage( &m_aTabCtrl
, this, DGTBinding
);
2004 pPage
= m_pBindingPage
;
2011 m_pInstPage
= new XFormsPage( &m_aTabCtrl
, this, DGTInstance
);
2012 pPage
= m_pInstPage
;
2017 if ( rCurId
> TID_INSTANCE
)
2019 sal_uInt16 nPos
= m_aTabCtrl
.GetPagePos( rCurId
);
2020 if ( HasFirstInstancePage() && nPos
> 0 )
2022 if ( m_aPageList
.size() > nPos
)
2023 pPage
= m_aPageList
[nPos
];
2026 pPage
= new XFormsPage( &m_aTabCtrl
, this, DGTInstance
);
2027 m_aPageList
.push_back( pPage
);
2033 // -----------------------------------------------------------------------
2034 void DataNavigatorWindow::LoadModels()
2036 if ( !m_xFrameModel
.is() )
2038 // get model of active frame
2039 Reference
< XController
> xCtrl
= m_xFrame
->getController();
2044 m_xFrameModel
= xCtrl
->getModel();
2046 catch ( Exception
& )
2048 SAL_WARN( "svx.form", "DataNavigatorWindow::LoadModels(): exception caught" );
2053 if ( m_xFrameModel
.is() )
2057 Reference
< css::xforms::XFormsSupplier
> xFormsSupp( m_xFrameModel
, UNO_QUERY
);
2058 if ( xFormsSupp
.is() )
2060 Reference
< XNameContainer
> xContainer
= xFormsSupp
->getXForms();
2061 if ( xContainer
.is() )
2063 m_xDataContainer
= xContainer
;
2064 Sequence
< OUString
> aNameList
= m_xDataContainer
->getElementNames();
2065 sal_Int32 i
, nCount
= aNameList
.getLength();
2066 OUString
* pNames
= aNameList
.getArray();
2067 for ( i
= 0; i
< nCount
; ++i
)
2069 Any aAny
= m_xDataContainer
->getByName( pNames
[i
] );
2070 Reference
< css::xforms::XModel
> xFormsModel
;
2071 if ( aAny
>>= xFormsModel
)
2072 m_aModelsBox
.InsertEntry( xFormsModel
->getID() );
2079 SAL_WARN( "svx.form", "DataNavigatorWindow::LoadModels(): exception caught" );
2083 if ( m_aModelsBox
.GetEntryCount() > 0 )
2085 m_aModelsBox
.SelectEntryPos(0);
2086 ModelSelectHdl( &m_aModelsBox
);
2089 // -----------------------------------------------------------------------
2090 void DataNavigatorWindow::SetPageModel()
2092 OUString
sModel( m_aModelsBox
.GetSelectEntry() );
2095 Any aAny
= m_xDataContainer
->getByName( sModel
);
2096 Reference
< css::xforms::XModel
> xFormsModel
;
2097 if ( aAny
>>= xFormsModel
)
2099 sal_uInt16 nPagePos
= TAB_PAGE_NOTFOUND
;
2101 XFormsPage
* pPage
= GetCurrentPage( nId
);
2102 DBG_ASSERT( pPage
, "DataNavigatorWindow::SetPageModel(): no page" );
2103 if ( nId
>= TID_INSTANCE
)
2105 nPagePos
= m_aTabCtrl
.GetPagePos( nId
);
2106 m_bIsNotifyDisabled
= true;
2107 String sText
= pPage
->SetModel( xFormsModel
, nPagePos
);
2108 m_bIsNotifyDisabled
= false;
2109 if ( sText
.Len() > 0 )
2110 m_aTabCtrl
.SetPageText( nId
, sText
);
2113 catch ( NoSuchElementException
& )
2115 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" );
2119 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): unexpected exception" );
2122 // -----------------------------------------------------------------------
2123 void DataNavigatorWindow::InitPages()
2125 OUString
sModel( m_aModelsBox
.GetSelectEntry() );
2128 Any aAny
= m_xDataContainer
->getByName( sModel
);
2129 Reference
< css::xforms::XModel
> xModel
;
2130 if ( aAny
>>= xModel
)
2132 Reference
< XEnumerationAccess
> xNumAccess( xModel
->getInstances(), UNO_QUERY
);
2133 if ( xNumAccess
.is() )
2135 Reference
< XEnumeration
> xNum
= xNumAccess
->createEnumeration();
2136 if ( xNum
.is() && xNum
->hasMoreElements() )
2138 sal_Int32 nAlreadyLoadedCount
= m_aPageList
.size();
2139 if ( !HasFirstInstancePage() && nAlreadyLoadedCount
> 0 )
2140 nAlreadyLoadedCount
--;
2142 while ( xNum
->hasMoreElements() )
2144 if ( nIdx
> nAlreadyLoadedCount
)
2146 Sequence
< PropertyValue
> xPropSeq
;
2147 if ( xNum
->nextElement() >>= xPropSeq
)
2148 CreateInstancePage( xPropSeq
);
2151 SAL_WARN( "svx.form", "DataNavigator::InitPages(): invalid instance" );
2155 xNum
->nextElement();
2162 catch ( NoSuchElementException
& )
2164 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): no such element" );
2168 SAL_WARN( "svx.form", "DataNavigatorWindow::SetPageModel(): unexpected exception" );
2171 // -----------------------------------------------------------------------
2172 void DataNavigatorWindow::ClearAllPageModels( bool bClearPages
)
2175 m_pInstPage
->ClearModel();
2176 if ( m_pSubmissionPage
)
2177 m_pSubmissionPage
->ClearModel();
2178 if ( m_pBindingPage
)
2179 m_pBindingPage
->ClearModel();
2181 sal_Int32 i
, nCount
= m_aPageList
.size();
2182 for ( i
= 0; i
< nCount
; ++i
)
2184 XFormsPage
* pPage
= m_aPageList
[i
];
2185 pPage
->ClearModel();
2192 m_aPageList
.clear();
2193 while ( m_aTabCtrl
.GetPageCount() > MIN_PAGE_COUNT
)
2194 m_aTabCtrl
.RemovePage( m_aTabCtrl
.GetPageId( 1 ) );
2197 // -----------------------------------------------------------------------
2198 void DataNavigatorWindow::CreateInstancePage( const Sequence
< PropertyValue
>& _xPropSeq
)
2201 OUString
sID( PN_INSTANCE_ID
);
2202 const PropertyValue
* pProps
= _xPropSeq
.getConstArray();
2203 const PropertyValue
* pPropsEnd
= pProps
+ _xPropSeq
.getLength();
2204 for ( ; pProps
!= pPropsEnd
; ++pProps
)
2206 if ( sID
== pProps
->Name
)
2208 pProps
->Value
>>= sInstName
;
2213 sal_uInt16 nPageId
= GetNewPageId();
2214 if ( sInstName
.isEmpty() )
2216 SAL_WARN( "svx.form", "DataNavigatorWindow::CreateInstancePage(): instance without name" );
2217 String sTemp
= OUString("untitled");
2218 sTemp
+= OUString::number( nPageId
);
2221 m_aTabCtrl
.InsertPage( nPageId
, sInstName
, m_aTabCtrl
.GetPageCount() - 2 );
2224 //------------------------------------------------------------------------
2225 bool DataNavigatorWindow::HasFirstInstancePage() const
2227 return ( m_aTabCtrl
.GetPageId( 0 ) == TID_INSTANCE
);
2230 //------------------------------------------------------------------------
2231 sal_uInt16
DataNavigatorWindow::GetNewPageId() const
2233 sal_uInt16 i
, nMax
= 0, nCount
= m_aTabCtrl
.GetPageCount();
2234 for ( i
= 0; i
< nCount
; ++i
)
2236 if ( nMax
< m_aTabCtrl
.GetPageId(i
) )
2237 nMax
= m_aTabCtrl
.GetPageId(i
);
2239 return ( nMax
+ 1 );
2242 //------------------------------------------------------------------------
2243 void DataNavigatorWindow::Resize()
2247 Size aOutSz
= GetOutputSizePixel();
2248 long nWidth
= std::max( aOutSz
.Width(), m_nMinWidth
);
2249 long nHeight
= std::max( aOutSz
.Height(), m_nMinHeight
);
2251 Size aSz
= m_aModelsBox
.GetSizePixel();
2252 aSz
.Width() = nWidth
- 3*m_a3Size
.Width() - m_aModelBtn
.GetSizePixel().Width();
2253 m_aModelsBox
.SetSizePixel( aSz
);
2254 Point aPos
= m_aModelBtn
.GetPosPixel();
2255 aPos
.X() = m_aModelsBox
.GetPosPixel().X() + aSz
.Width() + m_a3Size
.Width();
2256 m_aModelBtn
.SetPosPixel( aPos
);
2258 aSz
= m_aTabCtrl
.GetSizePixel();
2259 aSz
.Width() = nWidth
- 2*m_a3Size
.Width();
2260 aSz
.Height() = nHeight
- m_nBorderHeight
;
2261 m_aTabCtrl
.SetSizePixel( aSz
);
2262 // Instance button positioning
2263 aPos
= m_aInstanceBtn
.GetPosPixel();
2265 aPos
.X() = nWidth
- m_aInstanceBtn
.GetSizePixel().Width() - m_a3Size
.Width();
2266 // under the tabcontrol
2267 aPos
.Y() = m_aTabCtrl
.GetPosPixel().Y() + aSz
.Height() + m_a3Size
.Height();
2268 m_aInstanceBtn
.SetPosPixel( aPos
);
2271 //------------------------------------------------------------------------
2272 void DataNavigatorWindow::SetDocModified()
2274 SfxObjectShell
* pCurrentDoc
= SfxObjectShell::Current();
2275 DBG_ASSERT( pCurrentDoc
, "DataNavigatorWindow::SetDocModified(): no objectshell" );
2276 if ( !pCurrentDoc
->IsModified() && pCurrentDoc
->IsEnableSetModified() )
2277 pCurrentDoc
->SetModified();
2280 //------------------------------------------------------------------------
2281 void DataNavigatorWindow::NotifyChanges( bool _bLoadAll
)
2283 if ( !m_bIsNotifyDisabled
)
2287 // reset all members
2288 RemoveBroadcaster();
2289 m_xDataContainer
.clear();
2290 m_xFrameModel
.clear();
2291 m_aModelsBox
.Clear();
2292 m_nLastSelectedPos
= LISTBOX_ENTRY_NOTFOUND
;
2297 m_aUpdateTimer
.Start();
2301 //------------------------------------------------------------------------
2302 void DataNavigatorWindow::AddContainerBroadcaster( const XContainer_ref
& xContainer
)
2304 Reference
< XContainerListener
> xListener(
2305 static_cast< XContainerListener
* >( m_xDataListener
.get() ), UNO_QUERY
);
2306 xContainer
->addContainerListener( xListener
);
2307 m_aContainerList
.push_back( xContainer
);
2310 //------------------------------------------------------------------------
2311 void DataNavigatorWindow::AddEventBroadcaster( const XEventTarget_ref
& xTarget
)
2313 Reference
< XEventListener
> xListener(
2314 static_cast< XEventListener
* >( m_xDataListener
.get() ), UNO_QUERY
);
2315 xTarget
->addEventListener( EVENTTYPE_CHARDATA
, xListener
, true );
2316 xTarget
->addEventListener( EVENTTYPE_CHARDATA
, xListener
, false );
2317 xTarget
->addEventListener( EVENTTYPE_ATTR
, xListener
, true );
2318 xTarget
->addEventListener( EVENTTYPE_ATTR
, xListener
, false );
2319 m_aEventTargetList
.push_back( xTarget
);
2322 //------------------------------------------------------------------------
2323 void DataNavigatorWindow::RemoveBroadcaster()
2325 Reference
< XContainerListener
> xContainerListener(
2326 static_cast< XContainerListener
* >( m_xDataListener
.get() ), UNO_QUERY
);
2327 sal_Int32 i
, nCount
= m_aContainerList
.size();
2328 for ( i
= 0; i
< nCount
; ++i
)
2329 m_aContainerList
[i
]->removeContainerListener( xContainerListener
);
2330 Reference
< XEventListener
> xEventListener(
2331 static_cast< XEventListener
* >( m_xDataListener
.get() ), UNO_QUERY
);
2332 nCount
= m_aEventTargetList
.size();
2333 for ( i
= 0; i
< nCount
; ++i
)
2335 m_aEventTargetList
[i
]->removeEventListener( EVENTTYPE_CHARDATA
, xEventListener
, true );
2336 m_aEventTargetList
[i
]->removeEventListener( EVENTTYPE_CHARDATA
, xEventListener
, false );
2337 m_aEventTargetList
[i
]->removeEventListener( EVENTTYPE_ATTR
, xEventListener
, true );
2338 m_aEventTargetList
[i
]->removeEventListener( EVENTTYPE_ATTR
, xEventListener
, false );
2342 //========================================================================
2343 // class DataNavigator
2344 //========================================================================
2345 DBG_NAME(DataNavigator
)
2346 //------------------------------------------------------------------------
2347 DataNavigator::DataNavigator( SfxBindings
* _pBindings
, SfxChildWindow
* _pMgr
, Window
* _pParent
) :
2349 SfxDockingWindow( _pBindings
, _pMgr
, _pParent
,
2350 WinBits(WB_STDMODELESS
|WB_SIZEABLE
|WB_ROLLABLE
|WB_3DLOOK
|WB_DOCKABLE
) ),
2351 SfxControllerItem( SID_FM_DATANAVIGATOR_CONTROL
, *_pBindings
),
2353 m_aDataWin( this, _pBindings
)
2356 DBG_CTOR(DataNavigator
,NULL
);
2358 SetHelpId( HID_DATA_NAVIGATOR_WIN
);
2359 SetText( SVX_RES( RID_STR_DATANAVIGATOR
) );
2361 Size aSize
= m_aDataWin
.GetOutputSizePixel();
2362 Size aLogSize
= PixelToLogic( aSize
, MAP_APPFONT
);
2363 SfxDockingWindow::SetFloatingSize( aLogSize
);
2368 //------------------------------------------------------------------------
2369 DataNavigator::~DataNavigator()
2371 DBG_DTOR(DataNavigator
,NULL
);
2374 //-----------------------------------------------------------------------
2375 void DataNavigator::Update( FmFormShell
* /*pFormShell*/ )
2378 //-----------------------------------------------------------------------
2379 void DataNavigator::StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
2381 if ( !pState
|| SID_FM_DATANAVIGATOR_CONTROL
!= nSID
)
2384 if ( eState
>= SFX_ITEM_AVAILABLE
)
2386 FmFormShell
* pShell
= PTR_CAST( FmFormShell
,((SfxObjectItem
*)pState
)->GetShell() );
2393 //-----------------------------------------------------------------------
2394 void DataNavigator::GetFocus()
2396 SfxDockingWindow::GetFocus();
2399 //-----------------------------------------------------------------------
2400 sal_Bool
DataNavigator::Close()
2403 return SfxDockingWindow::Close();
2406 //-----------------------------------------------------------------------
2407 Size
DataNavigator::CalcDockingSize( SfxChildAlignment eAlign
)
2409 if ( ( eAlign
== SFX_ALIGN_TOP
) || ( eAlign
== SFX_ALIGN_BOTTOM
) )
2412 return SfxDockingWindow::CalcDockingSize( eAlign
);
2415 //-----------------------------------------------------------------------
2416 SfxChildAlignment
DataNavigator::CheckAlignment( SfxChildAlignment eActAlign
, SfxChildAlignment eAlign
)
2420 case SFX_ALIGN_LEFT
:
2421 case SFX_ALIGN_RIGHT
:
2422 case SFX_ALIGN_NOALIGNMENT
:
2430 //------------------------------------------------------------------------
2431 void DataNavigator::Resize()
2433 SfxDockingWindow::Resize();
2435 Size aLogOutputSize
= PixelToLogic( GetOutputSizePixel(), MAP_APPFONT
);
2436 Size aLogExplSize
= aLogOutputSize
;
2437 aLogExplSize
.Width() -= 2;
2438 aLogExplSize
.Height() -= 2;
2440 Point aExplPos
= LogicToPixel( Point(1,1), MAP_APPFONT
);
2441 Size aExplSize
= LogicToPixel( aLogExplSize
, MAP_APPFONT
);
2443 m_aDataWin
.SetPosSizePixel( aExplPos
, aExplSize
);
2447 //========================================================================
2448 // class NavigatorFrameManager
2449 //========================================================================
2451 //-----------------------------------------------------------------------
2452 SFX_IMPL_DOCKINGWINDOW( DataNavigatorManager
, SID_FM_SHOW_DATANAVIGATOR
)
2454 //-----------------------------------------------------------------------
2455 DataNavigatorManager::DataNavigatorManager(
2456 Window
* _pParent
, sal_uInt16 _nId
, SfxBindings
* _pBindings
, SfxChildWinInfo
* _pInfo
) :
2458 SfxChildWindow( _pParent
, _nId
)
2461 pWindow
= new DataNavigator( _pBindings
, this, _pParent
);
2462 eChildAlignment
= SFX_ALIGN_RIGHT
;
2463 pWindow
->SetSizePixel( Size( 250, 400 ) );
2464 ( (SfxDockingWindow
*)pWindow
)->Initialize( _pInfo
);
2467 //========================================================================
2468 // class AddDataItemDialog
2469 //========================================================================
2471 AddDataItemDialog::AddDataItemDialog(
2472 Window
* pParent
, ItemNode
* _pNode
,
2473 const Reference
< css::xforms::XFormsUIHelper1
>& _rUIHelper
) :
2475 ModalDialog( pParent
, SVX_RES( RID_SVXDLG_ADD_DATAITEM
) ),
2477 m_aItemFL ( this, SVX_RES( FL_ITEM
) ),
2478 m_aNameFT ( this, SVX_RES( FT_NAME
) ),
2479 m_aNameED ( this, SVX_RES( ED_NAME
) ),
2480 m_aDefaultFT ( this, SVX_RES( FT_DEFAULT
) ),
2481 m_aDefaultED ( this, SVX_RES( ED_DEFAULT
) ),
2482 m_aDefaultBtn ( this, SVX_RES( PB_DEFAULT
) ),
2483 m_aSettingsFL ( this, SVX_RES( FL_SETTINGS
) ),
2484 m_aDataTypeFT ( this, SVX_RES( FT_DATATYPE
) ),
2485 m_aDataTypeLB ( this, SVX_RES( LB_DATATYPE
) ),
2486 m_aRequiredCB ( this, SVX_RES( CB_REQUIRED
) ),
2487 m_aRequiredBtn ( this, SVX_RES( PB_REQUIRED
) ),
2488 m_aRelevantCB ( this, SVX_RES( CB_RELEVANT
) ),
2489 m_aRelevantBtn ( this, SVX_RES( PB_RELEVANT
) ),
2490 m_aConstraintCB ( this, SVX_RES( CB_CONSTRAINT
) ),
2491 m_aConstraintBtn( this, SVX_RES( PB_CONSTRAINT
) ),
2492 m_aReadonlyCB ( this, SVX_RES( CB_READONLY
) ),
2493 m_aReadonlyBtn ( this, SVX_RES( PB_READONLY
) ),
2494 m_aCalculateCB ( this, SVX_RES( CB_CALCULATE
) ),
2495 m_aCalculateBtn ( this, SVX_RES( PB_CALCULATE
) ),
2496 m_aButtonsFL ( this, SVX_RES( FL_DATANAV_BTN
) ),
2497 m_aOKBtn ( this, SVX_RES( BTN_DATANAV_OK
) ),
2498 m_aEscBtn ( this, SVX_RES( BTN_DATANAV_ESC
) ),
2499 m_aHelpBtn ( this, SVX_RES( BTN_DATANAV_HELP
) ),
2501 m_xUIHelper ( _rUIHelper
),
2502 m_pItemNode ( _pNode
),
2503 m_eItemType ( DITNone
),
2504 m_sFL_Element ( SVX_RES( STR_FIXEDLINE_ELEMENT
) ),
2505 m_sFL_Attribute ( SVX_RES( STR_FIXEDLINE_ATTRIBUTE
) ),
2506 m_sFL_Binding ( SVX_RES( STR_FIXEDLINE_BINDING
) ),
2507 m_sFT_BindingExp( SVX_RES( STR_FIXEDTEXT_BINDING
) )
2511 m_aDataTypeLB
.SetDropDownLineCount( 10 );
2519 //------------------------------------------------------------------------
2520 AddDataItemDialog::~AddDataItemDialog()
2522 if ( m_xTempBinding
.is() )
2524 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
2529 Reference
< XSet
> xBindings
= xModel
->getBindings();
2530 if ( xBindings
.is() )
2531 xBindings
->remove( makeAny( m_xTempBinding
) );
2533 catch ( Exception
& )
2535 SAL_WARN( "svx.form", "AddDataItemDialog::Dtor(): exception caught" );
2539 if( m_xUIHelper
.is() && m_xBinding
.is() )
2541 // remove binding, if it does not convey 'useful' information
2542 m_xUIHelper
->removeBindingIfUseless( m_xBinding
);
2546 //------------------------------------------------------------------------
2547 IMPL_LINK( AddDataItemDialog
, CheckHdl
, CheckBox
*, pBox
)
2549 // Condition buttons are only enable if their check box is checked
2550 m_aReadonlyBtn
.Enable( m_aReadonlyCB
.IsChecked() );
2551 m_aRequiredBtn
.Enable( m_aRequiredCB
.IsChecked() );
2552 m_aRelevantBtn
.Enable( m_aRelevantCB
.IsChecked() );
2553 m_aConstraintBtn
.Enable( m_aConstraintCB
.IsChecked() );
2554 m_aCalculateBtn
.Enable( m_aCalculateCB
.IsChecked() );
2556 if ( pBox
&& m_xTempBinding
.is() )
2558 OUString sTemp
, sPropName
;
2559 if ( &m_aRequiredCB
== pBox
)
2560 sPropName
= PN_REQUIRED_EXPR
;
2561 else if ( &m_aRelevantCB
== pBox
)
2562 sPropName
= PN_RELEVANT_EXPR
;
2563 else if ( &m_aConstraintCB
== pBox
)
2564 sPropName
= PN_CONSTRAINT_EXPR
;
2565 else if ( &m_aReadonlyCB
== pBox
)
2566 sPropName
= PN_READONLY_EXPR
;
2567 else if ( &m_aCalculateCB
== pBox
)
2568 sPropName
= PN_CALCULATE_EXPR
;
2569 bool bIsChecked
= ( pBox
->IsChecked() != sal_False
);
2570 m_xTempBinding
->getPropertyValue( sPropName
) >>= sTemp
;
2571 if ( bIsChecked
&& sTemp
.isEmpty() )
2573 else if ( !bIsChecked
&& !sTemp
.isEmpty() )
2575 m_xTempBinding
->setPropertyValue( sPropName
, makeAny( sTemp
) );
2581 //------------------------------------------------------------------------
2582 IMPL_LINK( AddDataItemDialog
, ConditionHdl
, PushButton
*, pBtn
)
2584 OUString sTemp
, sPropName
;
2585 if ( &m_aDefaultBtn
== pBtn
)
2586 sPropName
= PN_BINDING_EXPR
;
2587 else if ( &m_aRequiredBtn
== pBtn
)
2588 sPropName
= PN_REQUIRED_EXPR
;
2589 else if ( &m_aRelevantBtn
== pBtn
)
2590 sPropName
= PN_RELEVANT_EXPR
;
2591 else if ( &m_aConstraintBtn
== pBtn
)
2592 sPropName
= PN_CONSTRAINT_EXPR
;
2593 else if ( &m_aReadonlyBtn
== pBtn
)
2594 sPropName
= PN_READONLY_EXPR
;
2595 else if ( &m_aCalculateBtn
== pBtn
)
2596 sPropName
= PN_CALCULATE_EXPR
;
2597 AddConditionDialog
aDlg( this, sPropName
, m_xTempBinding
);
2598 bool bIsDefBtn
= ( &m_aDefaultBtn
== pBtn
);
2601 sCondition
= m_aDefaultED
.GetText();
2604 m_xTempBinding
->getPropertyValue( sPropName
) >>= sTemp
;
2605 if ( sTemp
.isEmpty() )
2609 aDlg
.SetCondition( sCondition
);
2611 if ( aDlg
.Execute() == RET_OK
)
2613 String sNewCondition
= aDlg
.GetCondition();
2615 m_aDefaultED
.SetText( sNewCondition
);
2619 m_xTempBinding
->setPropertyValue(
2620 sPropName
, makeAny( OUString( sNewCondition
) ) );
2626 void copyPropSet( const Reference
< XPropertySet
>& xFrom
, Reference
< XPropertySet
>& xTo
)
2628 DBG_ASSERT( xFrom
.is(), "copyPropSet(): no source" );
2629 DBG_ASSERT( xTo
.is(), "copyPropSet(): no target" );
2633 // get property names & infos, and iterate over target properties
2634 Sequence
< Property
> aProperties
= xTo
->getPropertySetInfo()->getProperties();
2635 sal_Int32 nProperties
= aProperties
.getLength();
2636 const Property
* pProperties
= aProperties
.getConstArray();
2637 Reference
< XPropertySetInfo
> xFromInfo
= xFrom
->getPropertySetInfo();
2638 for ( sal_Int32 i
= 0; i
< nProperties
; ++i
)
2640 const OUString
& rName
= pProperties
[i
].Name
;
2642 // if both set have the property, copy the value
2643 // (catch and ignore exceptions, if any)
2644 if ( xFromInfo
->hasPropertyByName( rName
) )
2646 // don't set readonly properties
2647 Property aProperty
= xFromInfo
->getPropertyByName( rName
);
2648 if ( ( aProperty
.Attributes
& PropertyAttribute::READONLY
) == 0 )
2649 xTo
->setPropertyValue(rName
, xFrom
->getPropertyValue( rName
));
2651 // else: no property? then ignore.
2654 catch ( Exception
& )
2656 SAL_WARN( "svx.form", "copyPropSet(): exception caught" );
2660 //------------------------------------------------------------------------
2661 IMPL_LINK_NOARG(AddDataItemDialog
, OKHdl
)
2663 bool bIsHandleBinding
= ( DITBinding
== m_eItemType
);
2664 bool bIsHandleText
= ( DITText
== m_eItemType
);
2665 OUString
sNewName( m_aNameED
.GetText() );
2667 if ( ( !bIsHandleBinding
&& !bIsHandleText
&& !m_xUIHelper
->isValidXMLName( sNewName
) ) ||
2668 ( bIsHandleBinding
&& sNewName
.isEmpty() ) )
2670 // Error and don't close the dialog
2671 ErrorBox
aErrBox( this, SVX_RES( RID_ERR_INVALID_XMLNAME
) );
2672 OUString sMessText
= aErrBox
.GetMessText();
2673 sMessText
= sMessText
.replaceFirst( MSG_VARIABLE
, sNewName
);
2674 aErrBox
.SetMessText( sMessText
);
2679 OUString
sDataType( m_aDataTypeLB
.GetSelectEntry() );
2680 m_xTempBinding
->setPropertyValue( PN_BINDING_TYPE
, makeAny( sDataType
) );
2682 if ( bIsHandleBinding
)
2684 // copy properties from temp binding to original binding
2685 copyPropSet( m_xTempBinding
, m_pItemNode
->m_xPropSet
);
2688 OUString sValue
= m_aNameED
.GetText();
2689 m_pItemNode
->m_xPropSet
->setPropertyValue( PN_BINDING_ID
, makeAny( sValue
) );
2690 sValue
= m_aDefaultED
.GetText();
2691 m_pItemNode
->m_xPropSet
->setPropertyValue( PN_BINDING_EXPR
, makeAny( sValue
) );
2693 catch ( Exception
& )
2695 SAL_WARN( "svx.form", "AddDataDialog::OKHdl(): exception caught" );
2700 // copy properties from temp binding to original binding
2701 copyPropSet( m_xTempBinding
, m_xBinding
);
2704 if ( bIsHandleText
)
2705 m_xUIHelper
->setNodeValue( m_pItemNode
->m_xNode
, m_aDefaultED
.GetText() );
2708 Reference
< css::xml::dom::XNode
> xNewNode
=
2709 m_xUIHelper
->renameNode( m_pItemNode
->m_xNode
, m_aNameED
.GetText() );
2710 m_xUIHelper
->setNodeValue( xNewNode
, m_aDefaultED
.GetText() );
2711 m_pItemNode
->m_xNode
= xNewNode
;
2714 catch ( Exception
& )
2716 SAL_WARN( "svx.form", "AddDataDialog::OKHdl(): exception caught" );
2719 // then close the dialog
2720 EndDialog( RET_OK
);
2724 //------------------------------------------------------------------------
2725 void AddDataItemDialog::InitDialog()
2728 Link aLink
= LINK( this, AddDataItemDialog
, CheckHdl
);
2729 m_aRequiredCB
.SetClickHdl( aLink
);
2730 m_aRelevantCB
.SetClickHdl( aLink
);
2731 m_aConstraintCB
.SetClickHdl( aLink
);
2732 m_aReadonlyCB
.SetClickHdl( aLink
);
2733 m_aCalculateCB
.SetClickHdl( aLink
);
2735 aLink
= LINK( this, AddDataItemDialog
, ConditionHdl
);
2736 m_aDefaultBtn
.SetClickHdl( aLink
);
2737 m_aRequiredBtn
.SetClickHdl( aLink
);
2738 m_aRelevantBtn
.SetClickHdl( aLink
);
2739 m_aConstraintBtn
.SetClickHdl( aLink
);
2740 m_aReadonlyBtn
.SetClickHdl( aLink
);
2741 m_aCalculateBtn
.SetClickHdl( aLink
);
2743 m_aOKBtn
.SetClickHdl( LINK( this, AddDataItemDialog
, OKHdl
) );
2746 //------------------------------------------------------------------------
2747 void AddDataItemDialog::InitFromNode()
2751 if ( m_pItemNode
->m_xNode
.is() )
2755 // detect type of the node
2756 css::xml::dom::NodeType eChildType
= m_pItemNode
->m_xNode
->getNodeType();
2757 switch ( eChildType
)
2759 case css::xml::dom::NodeType_ATTRIBUTE_NODE
:
2760 m_eItemType
= DITAttribute
;
2762 case css::xml::dom::NodeType_ELEMENT_NODE
:
2763 m_eItemType
= DITElement
;
2765 case css::xml::dom::NodeType_TEXT_NODE
:
2766 m_eItemType
= DITText
;
2769 OSL_FAIL( "AddDataItemDialog::InitFronNode: cannot handle this node type!" );
2773 /** Get binding of the node and clone it
2774 Then use this temporary binding in the dialog.
2775 When the user click OK the temporary binding will be copied
2776 into the original binding.
2779 Reference
< css::xml::dom::XNode
> xNode
= m_pItemNode
->m_xNode
;
2780 m_xBinding
= m_xUIHelper
->getBindingForNode( xNode
, sal_True
);
2781 if ( m_xBinding
.is() )
2783 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
2786 m_xTempBinding
= m_xUIHelper
->cloneBindingAsGhost( m_xBinding
);
2787 Reference
< XSet
> xBindings
= xModel
->getBindings();
2788 if ( xBindings
.is() )
2789 xBindings
->insert( makeAny( m_xTempBinding
) );
2793 if ( m_eItemType
!= DITText
)
2795 OUString
sName( m_xUIHelper
->getNodeName( m_pItemNode
->m_xNode
) );
2796 m_aNameED
.SetText( sName
);
2798 m_aDefaultED
.SetText( m_pItemNode
->m_xNode
->getNodeValue() );
2802 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2805 else if ( m_pItemNode
->m_xPropSet
.is() )
2807 m_eItemType
= DITBinding
;
2808 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
2813 m_xTempBinding
= m_xUIHelper
->cloneBindingAsGhost( m_pItemNode
->m_xPropSet
);
2814 Reference
< XSet
> xBindings
= xModel
->getBindings();
2815 if ( xBindings
.is() )
2816 xBindings
->insert( makeAny( m_xTempBinding
) );
2818 catch ( Exception
& )
2820 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2826 Reference
< XPropertySetInfo
> xInfo
= m_pItemNode
->m_xPropSet
->getPropertySetInfo();
2827 if ( xInfo
->hasPropertyByName( PN_BINDING_ID
) )
2829 m_pItemNode
->m_xPropSet
->getPropertyValue( PN_BINDING_ID
) >>= sTemp
;
2830 m_aNameED
.SetText( sTemp
);
2831 m_pItemNode
->m_xPropSet
->getPropertyValue( PN_BINDING_EXPR
) >>= sTemp
;
2832 m_aDefaultED
.SetText( sTemp
);
2834 else if ( xInfo
->hasPropertyByName( PN_SUBMISSION_BIND
) )
2836 m_pItemNode
->m_xPropSet
->getPropertyValue( PN_SUBMISSION_ID
) >>= sTemp
;
2837 m_aNameED
.SetText( sTemp
);
2842 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2845 Size a3and1Sz
= LogicToPixel( Size( 3, 1 ), MAP_APPFONT
);
2846 Size aNewSz
= m_aDefaultED
.GetSizePixel();
2847 Point aNewPnt
= m_aDefaultED
.GetPosPixel();
2848 aNewPnt
.Y() += a3and1Sz
.Height();
2849 aNewSz
.Width() -= ( m_aDefaultBtn
.GetSizePixel().Width() + a3and1Sz
.Width() );
2850 m_aDefaultED
.SetPosSizePixel( aNewPnt
, aNewSz
);
2851 m_aDefaultBtn
.Show();
2854 if ( m_xTempBinding
.is() )
2859 if ( ( m_xTempBinding
->getPropertyValue( PN_REQUIRED_EXPR
) >>= sTemp
)
2860 && !sTemp
.isEmpty() )
2861 m_aRequiredCB
.Check( sal_True
);
2862 if ( ( m_xTempBinding
->getPropertyValue( PN_RELEVANT_EXPR
) >>= sTemp
)
2863 && !sTemp
.isEmpty() )
2864 m_aRelevantCB
.Check( sal_True
);
2865 if ( ( m_xTempBinding
->getPropertyValue( PN_CONSTRAINT_EXPR
) >>= sTemp
)
2866 && !sTemp
.isEmpty() )
2867 m_aConstraintCB
.Check( sal_True
);
2868 if ( ( m_xTempBinding
->getPropertyValue( PN_READONLY_EXPR
) >>= sTemp
)
2869 && !sTemp
.isEmpty() )
2870 m_aReadonlyCB
.Check( sal_True
);
2871 if ( ( m_xTempBinding
->getPropertyValue( PN_CALCULATE_EXPR
) >>= sTemp
)
2872 && !sTemp
.isEmpty() )
2873 m_aCalculateCB
.Check( sal_True
);
2875 catch ( Exception
& )
2877 SAL_WARN( "svx.form", "AddDataItemDialog::InitFromNode(): exception caught" );
2882 if ( DITText
== m_eItemType
)
2884 long nDelta
= m_aButtonsFL
.GetPosPixel().Y() - m_aSettingsFL
.GetPosPixel().Y();
2886 Window
* pWinsForHide
[] =
2888 &m_aSettingsFL
, &m_aDataTypeFT
, &m_aDataTypeLB
, &m_aRequiredCB
,
2889 &m_aRequiredBtn
, &m_aRelevantCB
, &m_aRelevantBtn
, &m_aConstraintCB
,
2890 &m_aConstraintBtn
, &m_aReadonlyCB
, &m_aReadonlyBtn
, &m_aCalculateCB
,
2893 Window
** pCurrent
= pWinsForHide
;
2894 for ( ; i
< sizeof( pWinsForHide
) / sizeof( pWinsForHide
[ 0 ] ); ++i
, ++pCurrent
)
2895 (*pCurrent
)->Hide();
2897 Window
* pWinsForMove
[] =
2899 &m_aButtonsFL
, &m_aOKBtn
, &m_aEscBtn
, &m_aHelpBtn
2901 pCurrent
= pWinsForMove
;
2902 for ( i
= 0; i
< sizeof( pWinsForMove
) / sizeof( pWinsForMove
[ 0 ] ); ++i
, ++pCurrent
)
2904 Point aNewPos
= (*pCurrent
)->GetPosPixel();
2905 aNewPos
.Y() -= nDelta
;
2906 (*pCurrent
)->SetPosPixel( aNewPos
);
2908 Size aNewWinSz
= GetSizePixel();
2909 aNewWinSz
.Height() -= nDelta
;
2910 SetSizePixel( aNewWinSz
);
2912 m_aNameFT
.Disable();
2913 m_aNameED
.Disable();
2917 //------------------------------------------------------------------------
2918 void AddDataItemDialog::InitDataTypeBox()
2920 if ( m_eItemType
!= DITText
)
2922 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
2927 Reference
< css::xforms::XDataTypeRepository
> xDataTypes
=
2928 xModel
->getDataTypeRepository();
2929 if ( xDataTypes
.is() )
2931 Sequence
< OUString
> aNameList
= xDataTypes
->getElementNames();
2932 sal_Int32 i
, nCount
= aNameList
.getLength();
2933 OUString
* pNames
= aNameList
.getArray();
2934 for ( i
= 0; i
< nCount
; ++i
)
2935 m_aDataTypeLB
.InsertEntry( pNames
[i
] );
2938 if ( m_xTempBinding
.is() )
2941 if ( m_xTempBinding
->getPropertyValue( PN_BINDING_TYPE
) >>= sTemp
)
2943 sal_uInt16 nPos
= m_aDataTypeLB
.GetEntryPos( String( sTemp
) );
2944 if ( LISTBOX_ENTRY_NOTFOUND
== nPos
)
2945 nPos
= m_aDataTypeLB
.InsertEntry( sTemp
);
2946 m_aDataTypeLB
.SelectEntryPos( nPos
);
2950 catch ( Exception
& )
2952 SAL_WARN( "svx.form", "AddDataItemDialog::InitDataTypeBox(): exception caught" );
2958 void AddDataItemDialog::InitText( DataItemType _eType
)
2966 sText
= m_sFL_Attribute
;
2972 sText
= m_sFL_Binding
;
2973 m_aDefaultFT
.SetText( m_sFT_BindingExp
);
2979 sText
= m_sFL_Element
;
2983 m_aItemFL
.SetText( sText
);
2986 //========================================================================
2987 // class AddConditionDialog
2988 //========================================================================
2990 AddConditionDialog::AddConditionDialog(
2991 Window
* pParent
, const OUString
& _rPropertyName
,
2992 const Reference
< XPropertySet
>& _rPropSet
) :
2994 ModalDialog( pParent
, SVX_RES( RID_SVXDLG_ADD_CONDITION
) ),
2996 m_aConditionFT ( this, SVX_RES( FT_CONDITION
) ),
2997 m_aConditionED ( this, SVX_RES( ED_CONDITION
) ),
2998 m_aResultFT ( this, SVX_RES( FT_RESULT
) ),
2999 m_aResultWin ( this, SVX_RES( FT_RESULT_PREVIEW
) ),
3000 m_aEditNamespacesBtn( this, SVX_RES( PB_EDIT_NAMESPACES
) ),
3001 m_aButtonsFL ( this, SVX_RES( FL_DATANAV_BTN
) ),
3002 m_aOKBtn ( this, SVX_RES( BTN_DATANAV_OK
) ),
3003 m_aEscBtn ( this, SVX_RES( BTN_DATANAV_ESC
) ),
3004 m_aHelpBtn ( this, SVX_RES( BTN_DATANAV_HELP
) ),
3006 m_sPropertyName ( _rPropertyName
),
3007 m_xBinding ( _rPropSet
)
3012 DBG_ASSERT( m_xBinding
.is(), "AddConditionDialog::Ctor(): no Binding" );
3014 m_aResultWin
.SetBackground( m_aConditionED
.GetBackground() );
3015 m_aConditionED
.SetModifyHdl( LINK( this, AddConditionDialog
, ModifyHdl
) );
3016 m_aEditNamespacesBtn
.SetClickHdl( LINK( this, AddConditionDialog
, EditHdl
) );
3017 m_aOKBtn
.SetClickHdl( LINK( this, AddConditionDialog
, OKHdl
) );
3018 m_aResultTimer
.SetTimeout( 500 );
3019 m_aResultTimer
.SetTimeoutHdl( LINK( this, AddConditionDialog
, ResultHdl
) );
3021 if ( !m_sPropertyName
.isEmpty() )
3026 if ( ( m_xBinding
->getPropertyValue( m_sPropertyName
) >>= sTemp
)
3027 && !sTemp
.isEmpty() )
3029 m_aConditionED
.SetText( sTemp
);
3033 //! m_xBinding->setPropertyValue( m_sPropertyName, makeAny( TRUE_VALUE ) );
3034 m_aConditionED
.SetText( TRUE_VALUE
);
3037 Reference
< css::xforms::XModel
> xModel
;
3038 if ( ( m_xBinding
->getPropertyValue( PN_BINDING_MODEL
) >>= xModel
) && xModel
.is() )
3039 m_xUIHelper
= Reference
< css::xforms::XFormsUIHelper1
>( xModel
, UNO_QUERY
);
3041 catch ( Exception
& )
3043 SAL_WARN( "svx.form", "AddConditionDialog::Ctor(): exception caught" );
3047 DBG_ASSERT( m_xUIHelper
.is(), "AddConditionDialog::Ctor(): no UIHelper" );
3048 ResultHdl( &m_aResultTimer
);
3051 //------------------------------------------------------------------------
3052 AddConditionDialog::~AddConditionDialog()
3056 //------------------------------------------------------------------------
3057 IMPL_LINK_NOARG(AddConditionDialog
, EditHdl
)
3059 Reference
< XNameContainer
> xNameContnr
;
3062 m_xBinding
->getPropertyValue( PN_BINDING_NAMESPACES
) >>= xNameContnr
;
3064 catch ( Exception
& )
3066 SAL_WARN( "svx.form", "AddDataItemDialog::EditHdl(): exception caught" );
3068 NamespaceItemDialog
aDlg( this, xNameContnr
);
3072 m_xBinding
->setPropertyValue( PN_BINDING_NAMESPACES
, makeAny( xNameContnr
) );
3074 catch ( Exception
& )
3076 SAL_WARN( "svx.form", "AddDataItemDialog::EditHdl(): exception caught" );
3081 //------------------------------------------------------------------------
3082 IMPL_LINK_NOARG(AddConditionDialog
, OKHdl
)
3087 if ( m_xBinding.is() )
3088 m_xBinding->setPropertyValue( m_sPropertyName, makeAny( OUString( m_aConditionED.GetText() ) ) );
3090 catch( const Exception& )
3092 SAL_WARN( "svx.form", "AddConditionDialog, OKHdl: caught an exception!" );
3095 EndDialog( RET_OK
);
3099 //------------------------------------------------------------------------
3100 IMPL_LINK_NOARG(AddConditionDialog
, ModifyHdl
)
3102 m_aResultTimer
.Start();
3106 //------------------------------------------------------------------------
3107 IMPL_LINK_NOARG(AddConditionDialog
, ResultHdl
)
3109 String sCondition
= comphelper::string::strip(m_aConditionED
.GetText(), ' ');
3111 if ( sCondition
.Len() > 0 )
3115 sResult
= m_xUIHelper
->getResultForExpression( m_xBinding
, ( m_sPropertyName
== PN_BINDING_EXPR
), sCondition
);
3117 catch ( Exception
& )
3119 SAL_WARN( "svx.form", "AddConditionDialog::ResultHdl(): exception caught" );
3122 m_aResultWin
.SetText( sResult
);
3126 //========================================================================
3127 // class NamespaceItemDialog
3128 //========================================================================
3130 NamespaceItemDialog::NamespaceItemDialog(
3131 AddConditionDialog
* _pCondDlg
, Reference
< XNameContainer
>& _rContainer
) :
3133 ModalDialog( _pCondDlg
, SVX_RES( RID_SVXDLG_NAMESPACE_ITEM
) ),
3135 m_aNamespacesFT ( this, SVX_RES( FT_NAMESPACES
) ),
3136 m_aNamespacesListContainer ( this, SVX_RES( LB_NAMESPACES
) ),
3137 m_aNamespacesList ( m_aNamespacesListContainer
),
3138 m_aAddNamespaceBtn ( this, SVX_RES( PB_ADD_NAMESPACE
) ),
3139 m_aEditNamespaceBtn ( this, SVX_RES( PB_EDIT_NAMESPACE
) ),
3140 m_aDeleteNamespaceBtn ( this, SVX_RES( PB_DELETE_NAMESPACE
) ),
3141 m_aButtonsFL ( this, SVX_RES( FL_DATANAV_BTN
) ),
3142 m_aOKBtn ( this, SVX_RES( BTN_DATANAV_OK
) ),
3143 m_aEscBtn ( this, SVX_RES( BTN_DATANAV_ESC
) ),
3144 m_aHelpBtn ( this, SVX_RES( BTN_DATANAV_HELP
) ),
3146 m_pConditionDlg ( _pCondDlg
),
3147 m_rNamespaces ( _rContainer
)
3150 static long aStaticTabs
[]= { 3, 0, 35, 200 };
3151 m_aNamespacesList
.SvxSimpleTable::SetTabs( aStaticTabs
);
3152 String sHeader
= String( SVX_RES( STR_HEADER_PREFIX
) );
3154 sHeader
+= String( SVX_RES( STR_HEADER_URL
) );
3155 m_aNamespacesList
.InsertHeaderEntry(
3156 sHeader
, HEADERBAR_APPEND
, HIB_LEFT
/*| HIB_FIXEDPOS | HIB_FIXED*/ );
3160 m_aNamespacesList
.SetSelectHdl( LINK( this, NamespaceItemDialog
, SelectHdl
) );
3161 Link aLink
= LINK( this, NamespaceItemDialog
, ClickHdl
);
3162 m_aAddNamespaceBtn
.SetClickHdl( aLink
);
3163 m_aEditNamespaceBtn
.SetClickHdl( aLink
);
3164 m_aDeleteNamespaceBtn
.SetClickHdl( aLink
);
3165 m_aOKBtn
.SetClickHdl( LINK( this, NamespaceItemDialog
, OKHdl
) );
3168 SelectHdl( &m_aNamespacesList
);
3171 //------------------------------------------------------------------------
3172 NamespaceItemDialog::~NamespaceItemDialog()
3176 //------------------------------------------------------------------------
3177 IMPL_LINK( NamespaceItemDialog
, SelectHdl
, SvxSimpleTable
*, EMPTYARG
)
3179 sal_Bool bEnable
= ( m_aNamespacesList
.FirstSelected() != NULL
);
3180 m_aEditNamespaceBtn
.Enable( bEnable
);
3181 m_aDeleteNamespaceBtn
.Enable( bEnable
);
3186 //------------------------------------------------------------------------
3187 IMPL_LINK( NamespaceItemDialog
, ClickHdl
, PushButton
*, pBtn
)
3189 if ( &m_aAddNamespaceBtn
== pBtn
)
3191 ManageNamespaceDialog
aDlg( this, m_pConditionDlg
, false );
3192 if ( aDlg
.Execute() == RET_OK
)
3194 String sEntry
= aDlg
.GetPrefix();
3196 sEntry
+= aDlg
.GetURL();
3197 m_aNamespacesList
.InsertEntry( sEntry
);
3200 else if ( &m_aEditNamespaceBtn
== pBtn
)
3202 ManageNamespaceDialog
aDlg( this, m_pConditionDlg
, true );
3203 SvTreeListEntry
* pEntry
= m_aNamespacesList
.FirstSelected();
3204 DBG_ASSERT( pEntry
, "NamespaceItemDialog::ClickHdl(): no entry" );
3205 String
sPrefix( m_aNamespacesList
.GetEntryText( pEntry
, 0 ) );
3208 m_aNamespacesList
.GetEntryText( pEntry
, 1 ) );
3209 if ( aDlg
.Execute() == RET_OK
)
3211 // if a prefix was changed, mark the old prefix as 'removed'
3212 if( sPrefix
!= aDlg
.GetPrefix() )
3213 m_aRemovedList
.push_back( sPrefix
);
3215 m_aNamespacesList
.SetEntryText( aDlg
.GetPrefix(), pEntry
, 0 );
3216 m_aNamespacesList
.SetEntryText( aDlg
.GetURL(), pEntry
, 1 );
3219 else if ( &m_aDeleteNamespaceBtn
== pBtn
)
3221 SvTreeListEntry
* pEntry
= m_aNamespacesList
.FirstSelected();
3222 DBG_ASSERT( pEntry
, "NamespaceItemDialog::ClickHdl(): no entry" );
3223 OUString
sPrefix( m_aNamespacesList
.GetEntryText( pEntry
, 0 ) );
3224 m_aRemovedList
.push_back( sPrefix
);
3225 m_aNamespacesList
.GetModel()->Remove( pEntry
);
3229 SAL_WARN( "svx.form", "NamespaceItemDialog::ClickHdl(): invalid button" );
3232 SelectHdl( &m_aNamespacesList
);
3236 //------------------------------------------------------------------------
3237 IMPL_LINK_NOARG(NamespaceItemDialog
, OKHdl
)
3241 // update namespace container
3242 sal_Int32 i
, nRemovedCount
= m_aRemovedList
.size();
3243 for( i
= 0; i
< nRemovedCount
; ++i
)
3244 m_rNamespaces
->removeByName( m_aRemovedList
[i
] );
3246 sal_Int32 nEntryCount
= m_aNamespacesList
.GetEntryCount();
3247 for( i
= 0; i
< nEntryCount
; ++i
)
3249 SvTreeListEntry
* pEntry
= m_aNamespacesList
.GetEntry(i
);
3250 OUString
sPrefix( m_aNamespacesList
.GetEntryText( pEntry
, 0 ) );
3251 OUString
sURL( m_aNamespacesList
.GetEntryText( pEntry
, 1 ) );
3253 if ( m_rNamespaces
->hasByName( sPrefix
) )
3254 m_rNamespaces
->replaceByName( sPrefix
, makeAny( sURL
) );
3256 m_rNamespaces
->insertByName( sPrefix
, makeAny( sURL
) );
3259 catch ( Exception
& )
3261 SAL_WARN( "svx.form", "NamespaceItemDialog::OKHdl(): exception caught" );
3263 // and close the dialog
3264 EndDialog( RET_OK
);
3268 //------------------------------------------------------------------------
3269 void NamespaceItemDialog::LoadNamespaces()
3273 Sequence
< OUString
> aAllNames
= m_rNamespaces
->getElementNames();
3274 const OUString
* pAllNames
= aAllNames
.getConstArray();
3275 const OUString
* pAllNamesEnd
= pAllNames
+ aAllNames
.getLength();
3276 for ( ; pAllNames
!= pAllNamesEnd
; ++pAllNames
)
3279 OUString sPrefix
= *pAllNames
;
3280 if ( m_rNamespaces
->hasByName( sPrefix
) )
3282 Any aAny
= m_rNamespaces
->getByName( sPrefix
);
3283 if ( aAny
>>= sURL
)
3285 String
sEntry( sPrefix
);
3287 sEntry
+= String( sURL
);
3289 m_aNamespacesList
.InsertEntry( sEntry
);
3294 catch ( Exception
& )
3296 SAL_WARN( "svx.form", "NamespaceItemDialog::LoadNamespaces(): exception caught" );
3300 //========================================================================
3301 // class ManageNamespaceDialog
3302 //========================================================================
3304 ManageNamespaceDialog::ManageNamespaceDialog(
3305 Window
* pParent
, AddConditionDialog
* _pCondDlg
, bool _bIsEdit
) :
3307 ModalDialog( pParent
, SVX_RES( RID_SVXDLG_MANAGE_NAMESPACE
) ),
3309 m_aPrefixFT ( this, SVX_RES( FT_PREFIX
) ),
3310 m_aPrefixED ( this, SVX_RES( ED_PREFIX
) ),
3311 m_aUrlFT ( this, SVX_RES( FT_URL
) ),
3312 m_aUrlED ( this, SVX_RES( ED_URL
) ),
3313 m_aButtonsFL ( this, SVX_RES( FL_DATANAV_BTN
) ),
3314 m_aOKBtn ( this, SVX_RES( BTN_DATANAV_OK
) ),
3315 m_aEscBtn ( this, SVX_RES( BTN_DATANAV_ESC
) ),
3316 m_aHelpBtn ( this, SVX_RES( BTN_DATANAV_HELP
) ),
3318 m_pConditionDlg ( _pCondDlg
)
3322 SetText( String( SVX_RES( STR_EDIT_TEXT
) ) );
3326 m_aOKBtn
.SetClickHdl( LINK( this, ManageNamespaceDialog
, OKHdl
) );
3329 //------------------------------------------------------------------------
3330 ManageNamespaceDialog::~ManageNamespaceDialog()
3334 //------------------------------------------------------------------------
3335 IMPL_LINK_NOARG(ManageNamespaceDialog
, OKHdl
)
3337 String sPrefix
= m_aPrefixED
.GetText();
3341 if ( !m_pConditionDlg
->GetUIHelper()->isValidPrefixName( sPrefix
) )
3343 ErrorBox
aErrBox( this, SVX_RES( RID_ERR_INVALID_XMLPREFIX
) );
3344 OUString sMessText
= aErrBox
.GetMessText();
3345 sMessText
= sMessText
.replaceFirst( MSG_VARIABLE
, sPrefix
);
3346 aErrBox
.SetMessText( sMessText
);
3351 catch ( Exception
& )
3353 SAL_WARN( "svx.form", "ManageNamespacesDialog::OKHdl(): exception caught" );
3356 // no error so close the dialog
3357 EndDialog( RET_OK
);
3361 //========================================================================
3362 // class AddSubmissionDialog
3363 //========================================================================
3365 AddSubmissionDialog::AddSubmissionDialog(
3366 Window
* pParent
, ItemNode
* _pNode
,
3367 const Reference
< css::xforms::XFormsUIHelper1
>& _rUIHelper
) :
3369 ModalDialog( pParent
, SVX_RES( RID_SVXDLG_ADD_SUBMISSION
) ),
3371 m_aSubmissionFL ( this, SVX_RES( FL_SUBMISSION
) ),
3372 m_aNameFT ( this, SVX_RES( FT_SUBMIT_NAME
) ),
3373 m_aNameED ( this, SVX_RES( ED_SUBMIT_NAME
) ),
3374 m_aActionFT ( this, SVX_RES( FT_SUBMIT_ACTION
) ),
3375 m_aActionED ( this, SVX_RES( ED_SUBMIT_ACTION
) ),
3376 m_aMethodFT ( this, SVX_RES( FT_SUBMIT_METHOD
) ),
3377 m_aMethodLB ( this, SVX_RES( LB_SUBMIT_METHOD
) ),
3378 m_aRefFT ( this, SVX_RES( FT_SUBMIT_REF
) ),
3379 m_aRefED ( this, SVX_RES( ED_SUBMIT_REF
) ),
3380 m_aRefBtn ( this, SVX_RES( PB_SUBMIT_REF
) ),
3381 m_aBindFT ( this, SVX_RES( FT_SUBMIT_BIND
) ),
3382 m_aBindLB ( this, SVX_RES( LB_SUBMIT_BIND
) ),
3383 m_aReplaceFT ( this, SVX_RES( FT_SUBMIT_REPLACE
) ),
3384 m_aReplaceLB ( this, SVX_RES( LB_SUBMIT_REPLACE
) ),
3386 m_aButtonsFL ( this, SVX_RES( FL_DATANAV_BTN
) ),
3387 m_aOKBtn ( this, SVX_RES( BTN_DATANAV_OK
) ),
3388 m_aEscBtn ( this, SVX_RES( BTN_DATANAV_ESC
) ),
3389 m_aHelpBtn ( this, SVX_RES( BTN_DATANAV_HELP
) ),
3391 m_pItemNode ( _pNode
),
3392 m_xUIHelper ( _rUIHelper
)
3395 FillAllBoxes(); // we need local resources here, so call before FreeResource!!!
3399 m_aRefBtn
.SetClickHdl( LINK( this, AddSubmissionDialog
, RefHdl
) );
3400 m_aOKBtn
.SetClickHdl( LINK( this, AddSubmissionDialog
, OKHdl
) );
3403 //------------------------------------------------------------------------
3404 AddSubmissionDialog::~AddSubmissionDialog()
3406 // #i38991# if we have added a binding, we need to remove it as well.
3407 if( m_xCreatedBinding
.is() && m_xUIHelper
.is() )
3408 m_xUIHelper
->removeBindingIfUseless( m_xCreatedBinding
);
3411 //------------------------------------------------------------------------
3412 IMPL_LINK_NOARG(AddSubmissionDialog
, RefHdl
)
3414 AddConditionDialog
aDlg( this, PN_BINDING_EXPR
, m_xTempBinding
);
3415 aDlg
.SetCondition( m_aRefED
.GetText() );
3416 if ( aDlg
.Execute() == RET_OK
)
3417 m_aRefED
.SetText( aDlg
.GetCondition() );
3422 //------------------------------------------------------------------------
3423 IMPL_LINK_NOARG(AddSubmissionDialog
, OKHdl
)
3425 OUString
sName(m_aNameED
.GetText());
3426 if(sName
.isEmpty()) {
3428 ErrorBox
aErrorBox(this,SVX_RES(RID_ERR_EMPTY_SUBMISSIONNAME
));
3429 aErrorBox
.SetText( Application::GetDisplayName() );
3430 aErrorBox
.Execute();
3434 if ( !m_xSubmission
.is() )
3436 DBG_ASSERT( !m_xNewSubmission
.is(),
3437 "AddSubmissionDialog::OKHdl(): new submission already exists" );
3439 // add a new submission
3440 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
3445 m_xNewSubmission
= xModel
->createSubmission();
3446 m_xSubmission
= Reference
< XPropertySet
>( m_xNewSubmission
, UNO_QUERY
);
3448 catch ( Exception
& )
3450 SAL_WARN( "svx.form", "AddSubmissionDialog::OKHdl(): exception caught" );
3455 if ( m_xSubmission
.is() )
3457 OUString sTemp
= m_aNameED
.GetText();
3460 m_xSubmission
->setPropertyValue( PN_SUBMISSION_ID
, makeAny( sTemp
) );
3461 sTemp
= m_aActionED
.GetText();
3462 m_xSubmission
->setPropertyValue( PN_SUBMISSION_ACTION
, makeAny( sTemp
) );
3463 sTemp
= lcl_MethodString::get().toAPI( m_aMethodLB
.GetSelectEntry() );
3464 m_xSubmission
->setPropertyValue( PN_SUBMISSION_METHOD
, makeAny( sTemp
) );
3465 sTemp
= m_aRefED
.GetText();
3466 m_xSubmission
->setPropertyValue( PN_SUBMISSION_REF
, makeAny( sTemp
) );
3467 String sEntry
= m_aBindLB
.GetSelectEntry();
3468 sEntry
.Erase( sEntry
.Search( ':' ) );
3470 m_xSubmission
->setPropertyValue( PN_SUBMISSION_BIND
, makeAny( sTemp
) );
3471 sTemp
= lcl_ReplaceString::get().toAPI( m_aReplaceLB
.GetSelectEntry() );
3472 m_xSubmission
->setPropertyValue( PN_SUBMISSION_REPLACE
, makeAny( sTemp
) );
3474 catch ( Exception
& )
3476 SAL_WARN( "svx.form", "AddSubmissionDialog::OKHdl(): exception caught" );
3480 EndDialog( RET_OK
);
3484 //------------------------------------------------------------------------
3485 void AddSubmissionDialog::FillAllBoxes()
3488 m_aMethodLB
.InsertEntry( String( SVX_RES( STR_METHOD_POST
) ) );
3489 m_aMethodLB
.InsertEntry( String( SVX_RES( STR_METHOD_PUT
) ) );
3490 m_aMethodLB
.InsertEntry( String( SVX_RES( STR_METHOD_GET
) ) );
3491 m_aMethodLB
.SelectEntryPos(0);
3494 Reference
< css::xforms::XModel
> xModel( m_xUIHelper
, UNO_QUERY
);
3499 Reference
< XEnumerationAccess
> xNumAccess( xModel
->getBindings(), UNO_QUERY
);
3500 if ( xNumAccess
.is() )
3502 Reference
< XEnumeration
> xNum
= xNumAccess
->createEnumeration();
3503 if ( xNum
.is() && xNum
->hasMoreElements() )
3505 String
sDelim( RTL_CONSTASCII_USTRINGPARAM( ": " ) );
3506 while ( xNum
->hasMoreElements() )
3508 Reference
< XPropertySet
> xPropSet
;
3509 Any aAny
= xNum
->nextElement();
3510 if ( aAny
>>= xPropSet
)
3514 xPropSet
->getPropertyValue( PN_BINDING_ID
) >>= sTemp
;
3515 sEntry
+= String( sTemp
);
3517 xPropSet
->getPropertyValue( PN_BINDING_EXPR
) >>= sTemp
;
3518 sEntry
+= String( sTemp
);
3519 m_aBindLB
.InsertEntry( sEntry
);
3521 if ( !m_xTempBinding
.is() )
3522 m_xTempBinding
= xPropSet
;
3528 catch ( Exception
& )
3530 SAL_WARN( "svx.form", "AddSubmissionDialog::FillAllBoxes(): exception caught" );
3534 // #i36342# we need a temporary binding; create one if no existing binding
3536 if( !m_xTempBinding
.is() )
3538 m_xCreatedBinding
= m_xUIHelper
->getBindingForNode(
3539 Reference
<css::xml::dom::XNode
>(
3540 xModel
->getDefaultInstance()->getDocumentElement(),
3543 m_xTempBinding
= m_xCreatedBinding
;
3547 m_aReplaceLB
.InsertEntry( String( SVX_RES( STR_REPLACE_NONE
) ) );
3548 m_aReplaceLB
.InsertEntry( String( SVX_RES( STR_REPLACE_INST
) ) );
3549 m_aReplaceLB
.InsertEntry( String( SVX_RES( STR_REPLACE_DOC
) ) );
3552 // init the controls with the values of the submission
3553 if ( m_pItemNode
&& m_pItemNode
->m_xPropSet
.is() )
3555 m_xSubmission
= m_pItemNode
->m_xPropSet
;
3559 m_xSubmission
->getPropertyValue( PN_SUBMISSION_ID
) >>= sTemp
;
3560 m_aNameED
.SetText( sTemp
);
3561 m_xSubmission
->getPropertyValue( PN_SUBMISSION_ACTION
) >>= sTemp
;
3562 m_aActionED
.SetText( sTemp
);
3563 m_xSubmission
->getPropertyValue( PN_SUBMISSION_REF
) >>= sTemp
;
3564 m_aRefED
.SetText( sTemp
);
3566 m_xSubmission
->getPropertyValue( PN_SUBMISSION_METHOD
) >>= sTemp
;
3567 sTemp
= lcl_MethodString::get().toUI( sTemp
);
3568 sal_uInt16 nPos
= m_aMethodLB
.GetEntryPos( String( sTemp
) );
3569 if ( LISTBOX_ENTRY_NOTFOUND
== nPos
)
3570 nPos
= m_aMethodLB
.InsertEntry( sTemp
);
3571 m_aMethodLB
.SelectEntryPos( nPos
);
3573 m_xSubmission
->getPropertyValue( PN_SUBMISSION_BIND
) >>= sTemp
;
3574 nPos
= m_aBindLB
.GetEntryPos( String( sTemp
) );
3575 if ( LISTBOX_ENTRY_NOTFOUND
== nPos
)
3576 nPos
= m_aBindLB
.InsertEntry( sTemp
);
3577 m_aBindLB
.SelectEntryPos( nPos
);
3579 m_xSubmission
->getPropertyValue( PN_SUBMISSION_REPLACE
) >>= sTemp
;
3580 sTemp
= lcl_ReplaceString::get().toUI( sTemp
);
3581 if ( sTemp
.isEmpty() )
3582 sTemp
= m_aReplaceLB
.GetEntry(0); // first entry == "none"
3583 nPos
= m_aReplaceLB
.GetEntryPos( String( sTemp
) );
3584 if ( LISTBOX_ENTRY_NOTFOUND
== nPos
)
3585 nPos
= m_aReplaceLB
.InsertEntry( sTemp
);
3586 m_aReplaceLB
.SelectEntryPos( nPos
);
3588 catch ( Exception
& )
3590 SAL_WARN( "svx.form", "AddSubmissionDialog::FillAllBoxes(): exception caught" );
3594 m_aRefBtn
.Enable( m_xTempBinding
.is() );
3597 //========================================================================
3598 // class AddModelDialog
3599 //========================================================================
3601 AddModelDialog::AddModelDialog( Window
* pParent
, bool _bEdit
) :
3603 ModalDialog( pParent
, SVX_RES( RID_SVXDLG_ADD_MODEL
) ),
3605 m_aModelFL ( this, SVX_RES( FL_MODEL
) ),
3606 m_aNameFT ( this, SVX_RES( FT_MODEL_NAME
) ),
3607 m_aNameED ( this, SVX_RES( ED_MODEL_NAME
) ),
3608 m_aModifyCB ( this, SVX_RES( CB_MODIFIES_DOCUMENT
) ),
3609 m_aButtonsFL ( this, SVX_RES( FL_DATANAV_BTN
) ),
3610 m_aOKBtn ( this, SVX_RES( BTN_DATANAV_OK
) ),
3611 m_aEscBtn ( this, SVX_RES( BTN_DATANAV_ESC
) ),
3612 m_aHelpBtn ( this, SVX_RES( BTN_DATANAV_HELP
) )
3616 SetText( String( SVX_RES( STR_EDIT_TEXT
) ) );
3621 AddModelDialog::~AddModelDialog()
3625 //========================================================================
3626 // class AddInstanceDialog
3627 //========================================================================
3629 AddInstanceDialog::AddInstanceDialog( Window
* pParent
, bool _bEdit
) :
3631 ModalDialog( pParent
, SVX_RES( RID_SVXDLG_ADD_INSTANCE
) ),
3633 m_aInstanceFL ( this, SVX_RES( FL_INSTANCE
) ),
3634 m_aNameFT ( this, SVX_RES( FT_INST_NAME
) ),
3635 m_aNameED ( this, SVX_RES( ED_INST_NAME
) ),
3636 m_aURLFT ( this, SVX_RES( FT_INST_URL
) ),
3637 m_aURLED ( this, SVX_RES( ED_INST_URL
) ),
3638 m_aFilePickerBtn ( this, SVX_RES( PB_FILEPICKER
) ),
3639 m_aLinkInstanceCB ( this, SVX_RES( CB_INST_LINKINST
) ),
3640 m_aButtonsFL ( this, SVX_RES( FL_DATANAV_BTN
) ),
3641 m_aOKBtn ( this, SVX_RES( BTN_DATANAV_OK
) ),
3642 m_aEscBtn ( this, SVX_RES( BTN_DATANAV_ESC
) ),
3643 m_aHelpBtn ( this, SVX_RES( BTN_DATANAV_HELP
) )
3647 SetText( String( SVX_RES( STR_EDIT_TEXT
) ) );
3651 m_aURLED
.DisableHistory();
3652 m_aFilePickerBtn
.SetClickHdl( LINK( this, AddInstanceDialog
, FilePickerHdl
) );
3654 // load the filter name from fps_office resource
3655 m_sAllFilterName
= String( ResId( STR_FILTERNAME_ALL
, *ResMgr::CreateResMgr("fps_office") ) );
3658 AddInstanceDialog::~AddInstanceDialog()
3662 //------------------------------------------------------------------------
3663 IMPL_LINK_NOARG(AddInstanceDialog
, FilePickerHdl
)
3665 ::sfx2::FileDialogHelper
aDlg(
3666 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, 0 );
3667 INetURLObject
aFile( SvtPathOptions().GetWorkPath() );
3669 aDlg
.AddFilter( m_sAllFilterName
, OUString(FILEDIALOG_FILTER_ALL
) );
3670 String
sFilterName( "XML" );
3671 aDlg
.AddFilter( sFilterName
, OUString("*.xml") );
3672 aDlg
.SetCurrentFilter( sFilterName
);
3673 aDlg
.SetDisplayDirectory( aFile
.GetMainURL( INetURLObject::NO_DECODE
) );
3675 if( aDlg
.Execute() == ERRCODE_NONE
)
3676 m_aURLED
.SetText( aDlg
.GetPath() );
3681 //========================================================================
3682 // class LinkedInstanceWarningBox
3683 //========================================================================
3685 LinkedInstanceWarningBox::LinkedInstanceWarningBox( Window
* pParent
) :
3687 MessBox( pParent
, SVX_RES( RID_QRY_LINK_WARNING
) )
3690 SetText( Application::GetDisplayName() );
3691 SetImage( QueryBox::GetStandardImage() );
3692 AddButton( SVX_RESSTR( RID_STR_DATANAV_LINKWARN_BUTTON
), RET_OK
, BUTTONDIALOG_DEFBUTTON
);
3693 AddButton( BUTTON_CANCEL
, RET_CANCEL
, BUTTONDIALOG_CANCELBUTTON
);
3696 //............................................................................
3697 } // namespace svxform
3698 //............................................................................
3701 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */