Update ooo320-m1
[ooovba.git] / basctl / source / basicide / baside3.cxx
blob211c105179b2d1d442463de73332f51cb7e0900e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: baside3.cxx,v $
10 * $Revision: 1.43 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
34 //svdraw.hxx
35 //#define _SVDRAW_HXX ***
36 #define _SDR_NOITEMS
37 #define _SDR_NOTOUCH
38 #define _SDR_NOTRANSFORM
39 #define _SDR_NOOBJECTS
40 //#define _SDR_NOVIEWS ***
41 #define _SDR_NOVIEWMARKER
42 #define _SDR_NODRAGMETHODS
43 //#define _SDR_NOUNDO ***
44 #define _SDR_NOXOUTDEV
46 #include <ide_pch.hxx>
49 #include <vector>
50 #include <basidesh.hrc>
51 #include <baside3.hxx>
52 #include <localizationmgr.hxx>
53 #include <accessibledialogwindow.hxx>
54 #include <dlged.hxx>
55 #include <dlgedmod.hxx>
56 #include <dlgedview.hxx>
57 #include <dlgeddef.hxx>
58 #include <propbrw.hxx>
60 #include <basobj.hxx>
61 #include <iderdll.hxx>
62 #include <basidesh.hxx>
63 #include <idetemp.hxx>
64 #include <helpid.hrc>
65 #include <bastype2.hxx>
66 #include <svx/svdview.hxx>
67 #include <svx/unolingu.hxx>
68 #include <tools/diagnose_ex.h>
69 #include <tools/urlobj.hxx>
70 #include <comphelper/processfactory.hxx>
71 #include <com/sun/star/container/XNameContainer.hpp>
72 #include <com/sun/star/beans/XPropertySet.hpp>
73 #include <xmlscript/xmldlg_imexp.hxx>
74 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
75 #include <com/sun/star/script/XLibraryContainer2.hpp>
76 #endif
77 #include <svtools/ehdl.hxx>
78 #include <svtools/langtab.hxx>
79 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
80 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
81 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
82 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
83 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
84 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
85 #include <com/sun/star/resource/XStringResourceResolver.hpp>
86 #include <com/sun/star/resource/StringResourceWithLocation.hpp>
87 #include <com/sun/star/task/XInteractionHandler.hpp>
88 #include <com/sun/star/script/XVBACompat.hpp>
90 using namespace comphelper;
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::uno;
93 using namespace ::com::sun::star::ucb;
94 using namespace ::com::sun::star::io;
95 using namespace ::com::sun::star::resource;
96 using namespace ::com::sun::star::ui::dialogs;
98 #if defined(MAC)
99 #define FILTERMASK_ALL "****"
100 #elif defined(OW) || defined(MTF)
101 #define FILTERMASK_ALL "*"
102 #elif defined(PM2)
103 #define FILTERMASK_ALL ""
104 #else
105 #define FILTERMASK_ALL "*.*"
106 #endif
108 DBG_NAME( DialogWindow )
110 TYPEINIT1( DialogWindow, IDEBaseWindow );
112 DialogWindow::DialogWindow( Window* pParent, const ScriptDocument& rDocument, String aLibName, String aName,
113 const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xDialogModel )
114 :IDEBaseWindow( pParent, rDocument, aLibName, aName )
115 ,pUndoMgr(NULL)
117 InitSettings( TRUE, TRUE, TRUE );
119 pEditor = new DlgEditor( rDocument.getDocument() );
120 pEditor->SetWindow( this );
121 // set vba mode on DialogModel ( allows it to work in 100thmm instead of MAP_APPFONT )
122 if ( rDocument.getDocument().is() )
124 uno::Reference< script::XVBACompat > xDocVBAMode( rDocument.getLibraryContainer( E_SCRIPTS ), uno::UNO_QUERY );
125 uno::Reference< script::XVBACompat > xDialogModelVBAMode( xDialogModel, uno::UNO_QUERY );
126 if ( xDocVBAMode.is() && xDialogModelVBAMode.is() )
127 xDialogModelVBAMode->setVBACompatModeOn( xDocVBAMode->getVBACompatModeOn() );
129 pEditor->SetDialog( xDialogModel );
131 // Undo einrichten
132 pUndoMgr = new SfxUndoManager;
134 Link aDummyLink;
135 aOldNotifyUndoActionHdl = pEditor->GetModel()->GetNotifyUndoActionHdl();
136 pEditor->GetModel()->SetNotifyUndoActionHdl(
137 LINK(this, DialogWindow, NotifyUndoActionHdl));
139 SetHelpId( HID_BASICIDE_DIALOGWINDOW );
141 // set readonly mode for readonly libraries
142 ::rtl::OUString aOULibName( aLibName );
143 Reference< script::XLibraryContainer2 > xDlgLibContainer( GetDocument().getLibraryContainer( E_DIALOGS ), UNO_QUERY );
144 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) )
145 SetReadOnly( TRUE );
147 if ( rDocument.isDocument() && rDocument.isReadOnly() )
148 SetReadOnly( TRUE );
151 DialogWindow::~DialogWindow()
153 delete pEditor;
154 delete pUndoMgr;
157 void DialogWindow::LoseFocus()
159 if ( IsModified() )
160 StoreData();
162 Window::LoseFocus();
167 void DialogWindow::Paint( const Rectangle& rRect )
169 pEditor->Paint( rRect );
174 void DialogWindow::Resize()
176 if ( GetHScrollBar() && GetVScrollBar() ) {
177 pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
183 void DialogWindow::MouseButtonDown( const MouseEvent& rMEvt )
185 pEditor->MouseButtonDown( rMEvt );
187 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
188 if ( pBindings )
189 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
194 void DialogWindow::MouseButtonUp( const MouseEvent& rMEvt )
196 pEditor->MouseButtonUp( rMEvt );
197 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
198 if( (pEditor->GetMode() == DLGED_INSERT) && !pEditor->IsCreateOK() )
200 pEditor->SetMode( DLGED_SELECT );
201 if ( pBindings )
202 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
204 if ( pBindings )
206 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
207 pBindings->Invalidate( SID_DOC_MODIFIED );
208 pBindings->Invalidate( SID_SAVEDOC );
214 void DialogWindow::MouseMove( const MouseEvent& rMEvt )
216 pEditor->MouseMove( rMEvt );
221 void DialogWindow::KeyInput( const KeyEvent& rKEvt )
223 if( rKEvt.GetKeyCode() == KEY_BACKSPACE )
225 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
226 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
227 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
228 if( pDispatcher )
230 pDispatcher->Execute( SID_BACKSPACE );
233 else
235 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
236 if( pBindings && rKEvt.GetKeyCode() == KEY_TAB )
237 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
239 if( !pEditor->KeyInput( rKEvt ) )
241 if( !SfxViewShell::Current()->KeyInput( rKEvt ) )
242 Window::KeyInput( rKEvt );
247 void DialogWindow::Command( const CommandEvent& rCEvt )
249 if ( ( rCEvt.GetCommand() == COMMAND_WHEEL ) ||
250 ( rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL ) ||
251 ( rCEvt.GetCommand() == COMMAND_AUTOSCROLL ) )
253 HandleScrollCommand( rCEvt, GetHScrollBar(), GetVScrollBar() );
255 else if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
257 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
258 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
259 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
260 if ( pDispatcher )
262 SdrView* pView = GetView();
263 if( !rCEvt.IsMouseEvent() && pView->AreObjectsMarked() )
265 Rectangle aMarkedRect( pView->GetMarkedRect() );
266 Point MarkedCenter( aMarkedRect.Center() );
267 Point PosPixel( LogicToPixel( MarkedCenter ) );
268 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED), this, &PosPixel );
270 else
272 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED) );
277 else
278 IDEBaseWindow::Command( rCEvt );
284 IMPL_LINK( DialogWindow, NotifyUndoActionHdl, SfxUndoAction *, pUndoAction )
286 (void)pUndoAction;
288 // not working yet for unocontrols
290 if (pUndoAction)
292 pUndoMgr->AddUndoAction( pUndoAction );
293 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
294 if ( pBindings )
295 pBindings->Invalidate( SID_UNDO );
299 return 0;
304 void __EXPORT DialogWindow::DoInit()
306 GetHScrollBar()->Show();
307 GetVScrollBar()->Show();
308 pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
313 void __EXPORT DialogWindow::DoScroll( ScrollBar* pCurScrollBar )
315 pEditor->DoScroll( pCurScrollBar );
318 void __EXPORT DialogWindow::GetState( SfxItemSet& rSet )
320 SfxWhichIter aIter(rSet);
321 for ( USHORT nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
323 switch ( nWh )
325 case SID_PASTE:
327 if ( !IsPasteAllowed() )
328 rSet.DisableItem( nWh );
330 if ( IsReadOnly() )
331 rSet.DisableItem( nWh );
333 break;
334 case SID_COPY:
336 // any object selected?
337 if ( !pEditor->GetView()->AreObjectsMarked() )
338 rSet.DisableItem( nWh );
340 break;
341 case SID_CUT:
342 case SID_DELETE:
343 case SID_BACKSPACE:
345 // any object selected?
346 if ( !pEditor->GetView()->AreObjectsMarked() )
347 rSet.DisableItem( nWh );
349 if ( IsReadOnly() )
350 rSet.DisableItem( nWh );
352 break;
353 case SID_REDO:
355 if ( !pUndoMgr->GetUndoActionCount() )
356 rSet.DisableItem( nWh );
358 break;
360 // Nur Dialogfenster:
361 case SID_DIALOG_TESTMODE:
363 // ist die IDE noch aktiv?
364 if( IDE_DLL()->GetShell()->GetFrame() )
366 rSet.Put( SfxBoolItem( SID_DIALOG_TESTMODE,
367 (pEditor->GetMode() == DLGED_TEST) ? TRUE : FALSE) );
369 else
370 rSet.Put( SfxBoolItem( SID_DIALOG_TESTMODE,FALSE ));
372 break;
374 case SID_CHOOSE_CONTROLS:
376 if ( IsReadOnly() )
378 rSet.DisableItem( nWh );
380 else
382 SfxAllEnumItem aItem( SID_CHOOSE_CONTROLS );
383 if ( GetEditor()->GetMode() == DLGED_SELECT )
384 aItem.SetValue( SVX_SNAP_SELECT );
385 else
387 USHORT nObj;
388 switch( pEditor->GetInsertObj() )
390 case OBJ_DLG_PUSHBUTTON: nObj = SVX_SNAP_PUSHBUTTON; break;
391 case OBJ_DLG_RADIOBUTTON: nObj = SVX_SNAP_RADIOBUTTON; break;
392 case OBJ_DLG_CHECKBOX: nObj = SVX_SNAP_CHECKBOX; break;
393 case OBJ_DLG_LISTBOX: nObj = SVX_SNAP_LISTBOX; break;
394 case OBJ_DLG_COMBOBOX: nObj = SVX_SNAP_COMBOBOX; break;
395 case OBJ_DLG_GROUPBOX: nObj = SVX_SNAP_GROUPBOX; break;
396 case OBJ_DLG_EDIT: nObj = SVX_SNAP_EDIT; break;
397 case OBJ_DLG_FIXEDTEXT: nObj = SVX_SNAP_FIXEDTEXT; break;
398 case OBJ_DLG_IMAGECONTROL: nObj = SVX_SNAP_IMAGECONTROL; break;
399 case OBJ_DLG_PROGRESSBAR: nObj = SVX_SNAP_PROGRESSBAR; break;
400 case OBJ_DLG_HSCROLLBAR: nObj = SVX_SNAP_HSCROLLBAR; break;
401 case OBJ_DLG_VSCROLLBAR: nObj = SVX_SNAP_VSCROLLBAR; break;
402 case OBJ_DLG_HFIXEDLINE: nObj = SVX_SNAP_HFIXEDLINE; break;
403 case OBJ_DLG_VFIXEDLINE: nObj = SVX_SNAP_VFIXEDLINE; break;
404 case OBJ_DLG_DATEFIELD: nObj = SVX_SNAP_DATEFIELD; break;
405 case OBJ_DLG_TIMEFIELD: nObj = SVX_SNAP_TIMEFIELD; break;
406 case OBJ_DLG_NUMERICFIELD: nObj = SVX_SNAP_NUMERICFIELD; break;
407 case OBJ_DLG_CURRENCYFIELD: nObj = SVX_SNAP_CURRENCYFIELD; break;
408 case OBJ_DLG_FORMATTEDFIELD: nObj = SVX_SNAP_FORMATTEDFIELD; break;
409 case OBJ_DLG_PATTERNFIELD: nObj = SVX_SNAP_PATTERNFIELD; break;
410 case OBJ_DLG_FILECONTROL: nObj = SVX_SNAP_FILECONTROL; break;
411 case OBJ_DLG_TREECONTROL: nObj = SVX_SNAP_TREECONTROL; break;
412 default: nObj = 0;
414 #ifdef DBG_UTIL
415 if( !nObj )
417 DBG_WARNING( "SID_CHOOSE_CONTROLS: Unbekannt!" );
419 #endif
420 aItem.SetValue( nObj );
423 rSet.Put( aItem );
426 break;
428 case SID_SHOW_PROPERTYBROWSER:
430 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
431 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
432 if ( pViewFrame && !pViewFrame->HasChildWindow( SID_SHOW_PROPERTYBROWSER ) && !pEditor->GetView()->AreObjectsMarked() )
433 rSet.DisableItem( nWh );
435 if ( IsReadOnly() )
436 rSet.DisableItem( nWh );
438 break;
445 void __EXPORT DialogWindow::ExecuteCommand( SfxRequest& rReq )
447 switch ( rReq.GetSlot() )
449 case SID_CUT:
450 if ( !IsReadOnly() )
452 GetEditor()->Cut();
453 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
454 if ( pBindings )
455 pBindings->Invalidate( SID_DOC_MODIFIED );
457 break;
458 case SID_DELETE:
459 if ( !IsReadOnly() )
461 GetEditor()->Delete();
462 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
463 if ( pBindings )
464 pBindings->Invalidate( SID_DOC_MODIFIED );
466 break;
467 case SID_COPY:
468 GetEditor()->Copy();
469 break;
470 case SID_PASTE:
471 if ( !IsReadOnly() )
473 GetEditor()->Paste();
474 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
475 if ( pBindings )
476 pBindings->Invalidate( SID_DOC_MODIFIED );
478 break;
479 case SID_CHOOSE_CONTROLS:
481 const SfxItemSet* pArgs = rReq.GetArgs();
482 DBG_ASSERT( pArgs, "Nix Args" );
484 const SfxAllEnumItem& rItem = (SfxAllEnumItem&)pArgs->Get( SID_CHOOSE_CONTROLS );
485 switch( rItem.GetValue() )
487 case SVX_SNAP_PUSHBUTTON:
489 GetEditor()->SetMode( DLGED_INSERT );
490 GetEditor()->SetInsertObj( OBJ_DLG_PUSHBUTTON );
492 break;
493 case SVX_SNAP_RADIOBUTTON:
495 GetEditor()->SetMode( DLGED_INSERT );
496 GetEditor()->SetInsertObj( OBJ_DLG_RADIOBUTTON );
498 break;
499 case SVX_SNAP_CHECKBOX:
501 GetEditor()->SetMode( DLGED_INSERT );
502 GetEditor()->SetInsertObj( OBJ_DLG_CHECKBOX);
504 break;
505 case SVX_SNAP_LISTBOX:
507 GetEditor()->SetMode( DLGED_INSERT );
508 GetEditor()->SetInsertObj( OBJ_DLG_LISTBOX );
510 break;
511 case SVX_SNAP_COMBOBOX:
513 GetEditor()->SetMode( DLGED_INSERT );
514 GetEditor()->SetInsertObj( OBJ_DLG_COMBOBOX );
516 break;
517 case SVX_SNAP_GROUPBOX:
519 GetEditor()->SetMode( DLGED_INSERT );
520 GetEditor()->SetInsertObj( OBJ_DLG_GROUPBOX );
522 break;
523 case SVX_SNAP_EDIT:
525 GetEditor()->SetMode( DLGED_INSERT );
526 GetEditor()->SetInsertObj( OBJ_DLG_EDIT );
528 break;
529 case SVX_SNAP_FIXEDTEXT:
531 GetEditor()->SetMode( DLGED_INSERT );
532 GetEditor()->SetInsertObj( OBJ_DLG_FIXEDTEXT );
534 break;
535 case SVX_SNAP_IMAGECONTROL:
537 GetEditor()->SetMode( DLGED_INSERT );
538 GetEditor()->SetInsertObj( OBJ_DLG_IMAGECONTROL );
540 break;
541 case SVX_SNAP_PROGRESSBAR:
543 GetEditor()->SetMode( DLGED_INSERT );
544 GetEditor()->SetInsertObj( OBJ_DLG_PROGRESSBAR );
546 break;
547 case SVX_SNAP_HSCROLLBAR:
549 GetEditor()->SetMode( DLGED_INSERT );
550 GetEditor()->SetInsertObj( OBJ_DLG_HSCROLLBAR );
552 break;
553 case SVX_SNAP_VSCROLLBAR:
555 GetEditor()->SetMode( DLGED_INSERT );
556 GetEditor()->SetInsertObj( OBJ_DLG_VSCROLLBAR );
558 break;
559 case SVX_SNAP_HFIXEDLINE:
561 GetEditor()->SetMode( DLGED_INSERT );
562 GetEditor()->SetInsertObj( OBJ_DLG_HFIXEDLINE );
564 break;
565 case SVX_SNAP_VFIXEDLINE:
567 GetEditor()->SetMode( DLGED_INSERT );
568 GetEditor()->SetInsertObj( OBJ_DLG_VFIXEDLINE );
570 break;
571 case SVX_SNAP_DATEFIELD:
573 GetEditor()->SetMode( DLGED_INSERT );
574 GetEditor()->SetInsertObj( OBJ_DLG_DATEFIELD );
576 break;
577 case SVX_SNAP_TIMEFIELD:
579 GetEditor()->SetMode( DLGED_INSERT );
580 GetEditor()->SetInsertObj( OBJ_DLG_TIMEFIELD );
582 break;
583 case SVX_SNAP_NUMERICFIELD:
585 GetEditor()->SetMode( DLGED_INSERT );
586 GetEditor()->SetInsertObj( OBJ_DLG_NUMERICFIELD );
588 break;
589 case SVX_SNAP_CURRENCYFIELD:
591 GetEditor()->SetMode( DLGED_INSERT );
592 GetEditor()->SetInsertObj( OBJ_DLG_CURRENCYFIELD );
594 break;
595 case SVX_SNAP_FORMATTEDFIELD:
597 GetEditor()->SetMode( DLGED_INSERT );
598 GetEditor()->SetInsertObj( OBJ_DLG_FORMATTEDFIELD );
600 break;
601 case SVX_SNAP_PATTERNFIELD:
603 GetEditor()->SetMode( DLGED_INSERT );
604 GetEditor()->SetInsertObj( OBJ_DLG_PATTERNFIELD );
606 break;
607 case SVX_SNAP_FILECONTROL:
609 GetEditor()->SetMode( DLGED_INSERT );
610 GetEditor()->SetInsertObj( OBJ_DLG_FILECONTROL );
612 break;
613 case SVX_SNAP_TREECONTROL:
615 GetEditor()->SetMode( DLGED_INSERT );
616 GetEditor()->SetInsertObj( OBJ_DLG_TREECONTROL );
618 break;
620 case SVX_SNAP_SELECT:
622 GetEditor()->SetMode( DLGED_SELECT );
624 break;
627 if ( rReq.GetModifier() & KEY_MOD1 )
629 if ( GetEditor()->GetMode() == DLGED_INSERT )
630 GetEditor()->CreateDefaultObject();
633 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
634 if ( pBindings )
635 pBindings->Invalidate( SID_DOC_MODIFIED );
637 break;
639 case SID_DIALOG_TESTMODE:
641 DlgEdMode eOldMode = GetEditor()->GetMode();
642 GetEditor()->SetMode( DLGED_TEST );
643 GetEditor()->SetMode( eOldMode );
644 rReq.Done();
645 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
646 if ( pBindings )
647 pBindings->Invalidate( SID_DIALOG_TESTMODE );
648 return;
650 case SID_EXPORT_DIALOG:
651 SaveDialog();
652 break;
654 case SID_IMPORT_DIALOG:
655 ImportDialog();
656 break;
659 rReq.Done();
662 Reference< container::XNameContainer > DialogWindow::GetDialog() const
664 return pEditor->GetDialog();
667 BOOL DialogWindow::RenameDialog( const String& rNewName )
669 if ( !BasicIDE::RenameDialog( this, GetDocument(), GetLibName(), GetName(), rNewName ) )
670 return FALSE;
672 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
673 if ( pBindings )
674 pBindings->Invalidate( SID_DOC_MODIFIED );
676 return TRUE;
679 void DialogWindow::DisableBrowser()
681 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
682 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
683 SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow(SID_SHOW_PROPERTYBROWSER) : NULL;
684 if( pChildWin )
685 ((PropBrw*)(pChildWin->GetWindow()))->Update( NULL );
688 void DialogWindow::UpdateBrowser()
690 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
691 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
692 SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow(SID_SHOW_PROPERTYBROWSER) : NULL;
693 if( pChildWin )
694 ((PropBrw*)(pChildWin->GetWindow()))->Update( pIDEShell );
697 static ::rtl::OUString aResourceResolverPropName =
698 ::rtl::OUString::createFromAscii( "ResourceResolver" );
700 BOOL DialogWindow::SaveDialog()
702 DBG_CHKTHIS( DialogWindow, 0 );
703 BOOL bDone = FALSE;
705 Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
706 Reference < XFilePicker > xFP;
707 if( xMSF.is() )
709 Sequence <Any> aServiceType(1);
710 aServiceType[0] <<= TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
711 xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
712 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
715 Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
716 xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, sal_False);
717 Any aValue;
718 aValue <<= (sal_Bool) sal_True;
719 xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
721 if ( aCurPath.Len() )
722 xFP->setDisplayDirectory ( aCurPath );
724 xFP->setDefaultName( ::rtl::OUString( GetName() ) );
726 String aDialogStr( IDEResId( RID_STR_STDDIALOGNAME ) );
727 Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
728 xFltMgr->appendFilter( aDialogStr, String( RTL_CONSTASCII_USTRINGPARAM( "*.xdl" ) ) );
729 xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
730 xFltMgr->setCurrentFilter( aDialogStr );
732 if( xFP->execute() == RET_OK )
734 Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
735 aCurPath = aPaths[0];
737 // export dialog model to xml
738 Reference< container::XNameContainer > xDialogModel = GetDialog();
739 Reference< XComponentContext > xContext;
740 Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
741 OSL_ASSERT( xProps.is() );
742 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
743 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().getDocument() );
744 Reference< XInputStream > xInput( xISP->createInputStream() );
746 Reference< XSimpleFileAccess > xSFI( xMSF->createInstance
747 ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY );
749 Reference< XOutputStream > xOutput;
752 if( xSFI->exists( aCurPath ) )
753 xSFI->kill( aCurPath );
754 xOutput = xSFI->openFileWrite( aCurPath );
756 catch( Exception& )
759 if( xOutput.is() )
761 Sequence< sal_Int8 > bytes;
762 sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() );
763 for (;;)
765 if( nRead )
766 xOutput->writeBytes( bytes );
768 nRead = xInput->readBytes( bytes, 1024 );
769 if (! nRead)
770 break;
772 bDone = true;
774 // With resource?
775 Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
776 Reference< resource::XStringResourceResolver > xStringResourceResolver;
777 if( xDialogModelPropSet.is() )
781 Any aResourceResolver = xDialogModelPropSet->getPropertyValue( aResourceResolverPropName );
782 aResourceResolver >>= xStringResourceResolver;
784 catch( beans::UnknownPropertyException& )
788 bool bResource = false;
789 if( xStringResourceResolver.is() )
791 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
792 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
793 if( nLocaleCount > 0 )
794 bResource = true;
797 if( bResource )
799 INetURLObject aURLObj( aCurPath );
800 aURLObj.removeExtension();
801 ::rtl::OUString aDialogName( aURLObj.getName() );
802 aURLObj.removeSegment();
803 ::rtl::OUString aURL( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
804 sal_Bool bReadOnly = sal_False;
805 ::rtl::OUString aComment( ::rtl::OUString::createFromAscii( "# " ) );
806 aComment += aDialogName;
807 aComment += ::rtl::OUString::createFromAscii( " strings" );
808 Reference< task::XInteractionHandler > xDummyHandler;
810 // Remove old properties files in case of overwriting Dialog files
811 if( xSFI->isFolder( aURL ) )
813 Sequence< ::rtl::OUString > aContentSeq = xSFI->getFolderContents( aURL, false );
815 ::rtl::OUString aDialogName_( aDialogName );
816 aDialogName_ += ::rtl::OUString::createFromAscii( "_" );
817 sal_Int32 nCount = aContentSeq.getLength();
818 const ::rtl::OUString* pFiles = aContentSeq.getConstArray();
819 for( int i = 0 ; i < nCount ; i++ )
821 ::rtl::OUString aCompleteName = pFiles[i];
822 rtl::OUString aPureName;
823 rtl::OUString aExtension;
824 sal_Int32 iDot = aCompleteName.lastIndexOf( '.' );
825 sal_Int32 iSlash = aCompleteName.lastIndexOf( '/' );
826 if( iDot != -1 )
828 sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0;
829 aPureName = aCompleteName.copy( iCopyFrom, iDot-iCopyFrom );
830 aExtension = aCompleteName.copy( iDot + 1 );
833 if( aExtension.equalsAscii( "properties" ) ||
834 aExtension.equalsAscii( "default" ) )
836 if( aPureName.indexOf( aDialogName_ ) == 0 )
840 xSFI->kill( aCompleteName );
842 catch( uno::Exception& )
849 Reference< XStringResourceWithLocation > xStringResourceWithLocation =
850 StringResourceWithLocation::create( xContext, aURL, bReadOnly,
851 xStringResourceResolver->getDefaultLocale(), aDialogName, aComment, xDummyHandler );
853 // Add locales
854 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
855 const lang::Locale* pLocales = aLocaleSeq.getConstArray();
856 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
857 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ )
859 const lang::Locale& rLocale = pLocales[ iLocale ];
860 xStringResourceWithLocation->newLocale( rLocale );
863 Reference< XStringResourceManager > xTargetStringResourceManager( xStringResourceWithLocation, uno::UNO_QUERY );
865 LocalizationMgr::copyResourceForDialog( xDialogModel,
866 xStringResourceResolver, xTargetStringResourceManager );
868 xStringResourceWithLocation->store();
871 else
872 ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_COULDNTWRITE) ) ).Execute();
875 return bDone;
878 extern bool localesAreEqual( const ::com::sun::star::lang::Locale& rLocaleLeft,
879 const ::com::sun::star::lang::Locale& rLocaleRight );
881 std::vector< lang::Locale > implGetLanguagesOnlyContainedInFirstSeq
882 ( Sequence< lang::Locale > aFirstSeq, Sequence< lang::Locale > aSecondSeq )
884 std::vector< lang::Locale > avRet;
886 const lang::Locale* pFirst = aFirstSeq.getConstArray();
887 const lang::Locale* pSecond = aSecondSeq.getConstArray();
888 sal_Int32 nFirstCount = aFirstSeq.getLength();
889 sal_Int32 nSecondCount = aSecondSeq.getLength();
891 for( sal_Int32 iFirst = 0 ; iFirst < nFirstCount ; iFirst++ )
893 const lang::Locale& rFirstLocale = pFirst[ iFirst ];
895 bool bAlsoContainedInSecondSeq = false;
896 for( sal_Int32 iSecond = 0 ; iSecond < nSecondCount ; iSecond++ )
898 const lang::Locale& rSecondLocale = pSecond[ iSecond ];
900 bool bMatch = localesAreEqual( rFirstLocale, rSecondLocale );
901 if( bMatch )
903 bAlsoContainedInSecondSeq = true;
904 break;
908 if( !bAlsoContainedInSecondSeq )
909 avRet.push_back( rFirstLocale );
912 return avRet;
916 class NameClashQueryBox : public MessBox
918 public:
919 NameClashQueryBox( Window* pParent,
920 const XubString& rTitle, const XubString& rMessage );
923 NameClashQueryBox::NameClashQueryBox( Window* pParent,
924 const XubString& rTitle, const XubString& rMessage )
925 : MessBox( pParent, 0, rTitle, rMessage )
927 if ( rTitle.Len() )
928 SetText( rTitle );
930 maMessText = rMessage;
932 AddButton( String( IDEResId( RID_STR_DLGIMP_CLASH_RENAME ) ), RET_YES,
933 BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_OKBUTTON | BUTTONDIALOG_FOCUSBUTTON );
934 AddButton( String( IDEResId( RID_STR_DLGIMP_CLASH_REPLACE ) ), RET_NO, 0 );
935 AddButton( BUTTON_CANCEL, RET_CANCEL, BUTTONDIALOG_CANCELBUTTON );
937 SetImage( GetSettings().GetStyleSettings().GetDialogColor().IsDark() ?
938 QueryBox::GetStandardImageHC() : QueryBox::GetStandardImage() );
942 class LanguageMismatchQueryBox : public MessBox
944 public:
945 LanguageMismatchQueryBox( Window* pParent,
946 const XubString& rTitle, const XubString& rMessage );
949 LanguageMismatchQueryBox::LanguageMismatchQueryBox( Window* pParent,
950 const XubString& rTitle, const XubString& rMessage )
951 : MessBox( pParent, 0, rTitle, rMessage )
953 if ( rTitle.Len() )
954 SetText( rTitle );
956 maMessText = rMessage;
957 AddButton( String( IDEResId( RID_STR_DLGIMP_MISMATCH_ADD ) ), RET_YES,
958 BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_OKBUTTON | BUTTONDIALOG_FOCUSBUTTON );
959 AddButton( String( IDEResId( RID_STR_DLGIMP_MISMATCH_OMIT ) ), RET_NO, 0 );
960 AddButton( BUTTON_CANCEL, RET_CANCEL, BUTTONDIALOG_CANCELBUTTON );
961 AddButton( BUTTON_HELP, BUTTONID_HELP, BUTTONDIALOG_HELPBUTTON, 4 );
963 SetImage( GetSettings().GetStyleSettings().GetDialogColor().IsDark() ?
964 QueryBox::GetStandardImageHC() : QueryBox::GetStandardImage() );
967 BOOL implImportDialog( Window* pWin, const String& rCurPath, const ScriptDocument& rDocument, const String& aLibName )
969 BOOL bDone = FALSE;
971 Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
972 Reference < XFilePicker > xFP;
973 if( xMSF.is() )
975 Sequence <Any> aServiceType(1);
976 aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE;
977 xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
978 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
981 Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
982 xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, sal_False);
983 Any aValue;
984 aValue <<= (sal_Bool) sal_True;
985 xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
987 String aCurPath( rCurPath );
988 if ( aCurPath.Len() )
989 xFP->setDisplayDirectory ( aCurPath );
991 String aDialogStr( IDEResId( RID_STR_STDDIALOGNAME ) );
992 Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
993 xFltMgr->appendFilter( aDialogStr, String( RTL_CONSTASCII_USTRINGPARAM( "*.xdl" ) ) );
994 xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
995 xFltMgr->setCurrentFilter( aDialogStr );
997 if( xFP->execute() == RET_OK )
999 Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
1000 aCurPath = aPaths[0];
1002 ::rtl::OUString aBasePath;
1003 ::rtl::OUString aOUCurPath( aCurPath );
1004 sal_Int32 iSlash = aOUCurPath.lastIndexOf( '/' );
1005 if( iSlash != -1 )
1006 aBasePath = aOUCurPath.copy( 0, iSlash + 1 );
1010 // create dialog model
1011 Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
1012 ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY_THROW );
1014 Reference< XSimpleFileAccess > xSFI( xMSF->createInstance
1015 ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY_THROW );
1017 Reference< XInputStream > xInput;
1018 if( xSFI->exists( aCurPath ) )
1019 xInput = xSFI->openFileRead( aCurPath );
1021 Reference< XComponentContext > xContext;
1022 Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
1023 OSL_ASSERT( xProps.is() );
1024 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
1025 ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.getDocument() );
1027 String aXmlDlgName;
1028 Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
1029 if( xDialogModelPropSet.is() )
1033 Any aXmlDialogNameAny = xDialogModelPropSet->getPropertyValue( DLGED_PROP_NAME );
1034 ::rtl::OUString aOUXmlDialogName;
1035 aXmlDialogNameAny >>= aOUXmlDialogName;
1036 aXmlDlgName = aOUXmlDialogName;
1038 catch( beans::UnknownPropertyException& )
1041 bool bValidName = (aXmlDlgName.Len() != 0);
1042 OSL_ASSERT( bValidName );
1043 if( !bValidName )
1044 return bDone;
1046 bool bDialogAlreadyExists = rDocument.hasDialog( aLibName, aXmlDlgName );
1048 String aNewDlgName = aXmlDlgName;
1049 enum NameClashMode
1051 NO_CLASH,
1052 CLASH_OVERWRITE_DIALOG,
1053 CLASH_RENAME_DIALOG,
1055 NameClashMode eNameClashMode = NO_CLASH;
1056 if( bDialogAlreadyExists )
1058 String aQueryBoxTitle( IDEResId( RID_STR_DLGIMP_CLASH_TITLE ) );
1059 String aQueryBoxText( IDEResId( RID_STR_DLGIMP_CLASH_TEXT ) );
1060 aQueryBoxText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "$(ARG1)" ) ), aXmlDlgName );
1062 NameClashQueryBox aQueryBox( pWin, aQueryBoxTitle, aQueryBoxText );
1063 USHORT nRet = aQueryBox.Execute();
1064 if( RET_YES == nRet )
1066 // RET_YES == Rename, see NameClashQueryBox::NameClashQueryBox
1067 eNameClashMode = CLASH_RENAME_DIALOG;
1069 aNewDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
1071 else if( RET_NO == nRet )
1073 // RET_NO == Replace, see NameClashQueryBox::NameClashQueryBox
1074 eNameClashMode = CLASH_OVERWRITE_DIALOG;
1076 else if( RET_CANCEL == nRet )
1078 return bDone;
1082 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
1083 if( pIDEShell == NULL )
1085 OSL_ASSERT( pIDEShell != NULL );
1086 return bDone;
1089 // Resource?
1090 ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
1091 Reference< task::XInteractionHandler > xDummyHandler;
1092 bool bReadOnly = true;
1093 Reference< XStringResourceWithLocation > xImportStringResource =
1094 StringResourceWithLocation::create( xContext, aBasePath, bReadOnly,
1095 aLocale, aXmlDlgName, ::rtl::OUString(), xDummyHandler );
1097 Sequence< lang::Locale > aImportLocaleSeq = xImportStringResource->getLocales();
1098 sal_Int32 nImportLocaleCount = aImportLocaleSeq.getLength();
1100 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, TRUE ) );
1101 Reference< resource::XStringResourceManager > xLibStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
1102 sal_Int32 nLibLocaleCount = 0;
1103 Sequence< lang::Locale > aLibLocaleSeq;
1104 if( xLibStringResourceManager.is() )
1106 aLibLocaleSeq = xLibStringResourceManager->getLocales();
1107 nLibLocaleCount = aLibLocaleSeq.getLength();
1110 // Check language matches
1111 std::vector< lang::Locale > aOnlyInImportLanguages =
1112 implGetLanguagesOnlyContainedInFirstSeq( aImportLocaleSeq, aLibLocaleSeq );
1113 int nOnlyInImportLanguageCount = aOnlyInImportLanguages.size();
1115 // For now: Keep languages from lib
1116 bool bLibLocalized = (nLibLocaleCount > 0);
1117 bool bImportLocalized = (nImportLocaleCount > 0);
1119 bool bAddDialogLanguagesToLib = false;
1120 if( nOnlyInImportLanguageCount > 0 )
1122 String aQueryBoxTitle( IDEResId( RID_STR_DLGIMP_MISMATCH_TITLE ) );
1123 String aQueryBoxText( IDEResId( RID_STR_DLGIMP_MISMATCH_TEXT ) );
1124 LanguageMismatchQueryBox aQueryBox( pWin, aQueryBoxTitle, aQueryBoxText );
1125 USHORT nRet = aQueryBox.Execute();
1126 if( RET_YES == nRet )
1128 // RET_YES == Add, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
1129 bAddDialogLanguagesToLib = true;
1131 // RET_NO == Omit, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
1132 // -> nothing to do here
1133 //else if( RET_NO == nRet )
1136 else if( RET_CANCEL == nRet )
1138 return bDone;
1142 if( bImportLocalized )
1144 bool bCopyResourcesForDialog = true;
1145 if( bAddDialogLanguagesToLib )
1147 LocalizationMgr* pCurMgr = pIDEShell->GetCurLocalizationMgr();
1149 lang::Locale aFirstLocale;
1150 aFirstLocale = aOnlyInImportLanguages[0];
1151 if( nOnlyInImportLanguageCount > 1 )
1153 // Check if import default belongs to only import languages and use it then
1154 lang::Locale aImportDefaultLocale = xImportStringResource->getDefaultLocale();
1155 lang::Locale aTmpLocale;
1156 for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
1158 aTmpLocale = aOnlyInImportLanguages[i];
1159 if( localesAreEqual( aImportDefaultLocale, aTmpLocale ) )
1161 aFirstLocale = aImportDefaultLocale;
1162 break;
1167 Sequence< lang::Locale > aFirstLocaleSeq( 1 );
1168 aFirstLocaleSeq[0] = aFirstLocale;
1169 pCurMgr->handleAddLocales( aFirstLocaleSeq );
1171 if( nOnlyInImportLanguageCount > 1 )
1173 Sequence< lang::Locale > aRemainingLocaleSeq( nOnlyInImportLanguageCount - 1 );
1174 lang::Locale aTmpLocale;
1175 int iSeq = 0;
1176 for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
1178 aTmpLocale = aOnlyInImportLanguages[i];
1179 if( !localesAreEqual( aFirstLocale, aTmpLocale ) )
1180 aRemainingLocaleSeq[iSeq++] = aTmpLocale;
1182 pCurMgr->handleAddLocales( aRemainingLocaleSeq );
1185 else if( !bLibLocalized )
1187 Reference< resource::XStringResourceManager > xImportStringResourceManager( xImportStringResource, UNO_QUERY );
1188 LocalizationMgr::resetResourceForDialog( xDialogModel, xImportStringResourceManager );
1189 bCopyResourcesForDialog = false;
1192 if( bCopyResourcesForDialog )
1194 Reference< resource::XStringResourceResolver > xImportStringResourceResolver( xImportStringResource, UNO_QUERY );
1195 LocalizationMgr::copyResourceForDroppedDialog( xDialogModel, aXmlDlgName,
1196 xLibStringResourceManager, xImportStringResourceResolver );
1199 else if( bLibLocalized )
1201 LocalizationMgr::setResourceIDsForDialog( xDialogModel, xLibStringResourceManager );
1205 LocalizationMgr::setStringResourceAtDialog( rDocument, aLibName, aNewDlgName, xDialogModel );
1207 if( eNameClashMode == CLASH_OVERWRITE_DIALOG )
1209 if ( BasicIDE::RemoveDialog( rDocument, aLibName, aNewDlgName ) )
1211 IDEBaseWindow* pDlgWin = pIDEShell->FindDlgWin( rDocument, aLibName, aNewDlgName, FALSE, TRUE );
1212 if( pDlgWin != NULL )
1213 pIDEShell->RemoveWindow( pDlgWin, TRUE );
1214 BasicIDE::MarkDocumentModified( rDocument );
1216 else
1218 // TODO: Assertion?
1219 return bDone;
1223 if( eNameClashMode == CLASH_RENAME_DIALOG )
1225 bool bRenamed = false;
1226 if( xDialogModelPropSet.is() )
1230 Any aXmlDialogNameAny;
1231 aXmlDialogNameAny <<= ::rtl::OUString( aNewDlgName );
1232 xDialogModelPropSet->setPropertyValue( DLGED_PROP_NAME, aXmlDialogNameAny );
1233 bRenamed = true;
1235 catch( beans::UnknownPropertyException& )
1240 if( bRenamed )
1242 LocalizationMgr::renameStringResourceIDs( rDocument, aLibName, aNewDlgName, xDialogModel );
1244 else
1246 // TODO: Assertion?
1247 return bDone;
1251 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, rDocument.getDocument() );
1252 bool bSuccess = rDocument.insertDialog( aLibName, aNewDlgName, xISP );
1253 if( bSuccess )
1255 DialogWindow* pNewDlgWin = pIDEShell->CreateDlgWin( rDocument, aLibName, aNewDlgName );
1256 pIDEShell->SetCurWindow( pNewDlgWin, TRUE );
1259 bDone = TRUE;
1261 catch( Exception& )
1265 return bDone;
1268 BOOL DialogWindow::ImportDialog()
1270 DBG_CHKTHIS( DialogWindow, 0 );
1272 const ScriptDocument& rDocument = GetDocument();
1273 String aLibName = GetLibName();
1274 BOOL bRet = implImportDialog( this, aCurPath, rDocument, aLibName );
1275 return bRet;
1278 DlgEdModel* DialogWindow::GetModel() const
1280 return pEditor ? pEditor->GetModel() : NULL;
1283 DlgEdPage* DialogWindow::GetPage() const
1285 return pEditor ? pEditor->GetPage() : NULL;
1288 DlgEdView* DialogWindow::GetView() const
1290 return pEditor ? pEditor->GetView() : NULL;
1293 BOOL __EXPORT DialogWindow::IsModified()
1295 return pEditor->IsModified();
1298 SfxUndoManager* __EXPORT DialogWindow::GetUndoManager()
1300 return pUndoMgr;
1303 String DialogWindow::GetTitle()
1305 return GetName();
1308 BasicEntryDescriptor DialogWindow::CreateEntryDescriptor()
1310 ScriptDocument aDocument( GetDocument() );
1311 String aLibName( GetLibName() );
1312 String aLibSubName;
1313 LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
1314 return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, GetName(), OBJ_TYPE_DIALOG );
1317 void DialogWindow::SetReadOnly( BOOL b )
1319 if ( pEditor )
1321 if ( b )
1322 pEditor->SetMode( DLGED_READONLY );
1323 else
1324 pEditor->SetMode( DLGED_SELECT );
1328 BOOL DialogWindow::IsReadOnly()
1330 BOOL bReadOnly = FALSE;
1332 if ( pEditor && pEditor->GetMode() == DLGED_READONLY )
1333 bReadOnly = TRUE;
1335 return bReadOnly;
1338 BOOL DialogWindow::IsPasteAllowed()
1340 return pEditor ? pEditor->IsPasteAllowed() : FALSE;
1343 void DialogWindow::StoreData()
1345 if ( IsModified() )
1349 Reference< container::XNameContainer > xLib = GetDocument().getLibrary( E_DIALOGS, GetLibName(), true );
1351 if( xLib.is() )
1353 Reference< container::XNameContainer > xDialogModel = pEditor->GetDialog();
1355 if( xDialogModel.is() )
1357 Reference< XComponentContext > xContext;
1358 Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
1359 OSL_ASSERT( xProps.is() );
1360 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
1361 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().getDocument() );
1362 xLib->replaceByName( ::rtl::OUString( GetName() ), makeAny( xISP ) );
1366 catch ( uno::Exception& )
1368 DBG_UNHANDLED_EXCEPTION();
1370 BasicIDE::MarkDocumentModified( GetDocument() );
1371 pEditor->ClearModifyFlag();
1375 void DialogWindow::Deactivating()
1377 if ( IsModified() )
1378 BasicIDE::MarkDocumentModified( GetDocument() );
1381 void DialogWindow::PrintData( Printer* pPrinter )
1383 pEditor->PrintData( pPrinter, CreateQualifiedName() );
1386 void DialogWindow::DataChanged( const DataChangedEvent& rDCEvt )
1388 if( (rDCEvt.GetType()==DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1390 InitSettings( TRUE, TRUE, TRUE );
1391 Invalidate();
1393 else
1394 IDEBaseWindow::DataChanged( rDCEvt );
1397 void DialogWindow::InitSettings(BOOL bFont,BOOL bForeground,BOOL bBackground)
1399 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1400 if( bFont )
1402 Font aFont;
1403 aFont = rStyleSettings.GetFieldFont();
1404 SetPointFont( aFont );
1407 if( bForeground || bFont )
1409 SetTextColor( rStyleSettings.GetFieldTextColor() );
1410 SetTextFillColor();
1413 if( bBackground )
1414 SetBackground( rStyleSettings.GetFieldColor() );
1417 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > DialogWindow::CreateAccessible()
1419 return (::com::sun::star::accessibility::XAccessible*) new AccessibleDialogWindow( this );