update dev300-m58
[ooovba.git] / basctl / source / basicide / baside3.cxx
blob0fcc3fff75fcb6d7c60cc29462a3480a124d2bae
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 <basidesh.hrc>
50 #include <baside3.hxx>
51 #include <localizationmgr.hxx>
52 #include <accessibledialogwindow.hxx>
53 #include <dlged.hxx>
54 #include <dlgedmod.hxx>
55 #include <dlgedview.hxx>
56 #include <dlgeddef.hxx>
57 #include <propbrw.hxx>
59 #include <basobj.hxx>
60 #include <iderdll.hxx>
61 #include <basidesh.hxx>
62 #include <idetemp.hxx>
63 #include <helpid.hrc>
64 #include <bastype2.hxx>
65 #include <svx/svdview.hxx>
66 #include <tools/diagnose_ex.h>
67 #include <tools/urlobj.hxx>
68 #include <comphelper/processfactory.hxx>
69 #include <com/sun/star/container/XNameContainer.hpp>
70 #include <com/sun/star/beans/XPropertySet.hpp>
71 #include <xmlscript/xmldlg_imexp.hxx>
72 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
73 #include <com/sun/star/script/XLibraryContainer2.hpp>
74 #endif
75 #include <svtools/ehdl.hxx>
76 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
77 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
78 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
79 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
80 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
81 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
82 #include <com/sun/star/resource/XStringResourceResolver.hpp>
83 #include <com/sun/star/resource/StringResourceWithLocation.hpp>
84 #include <com/sun/star/task/XInteractionHandler.hpp>
85 #include <com/sun/star/script/XVBACompat.hpp>
87 using namespace comphelper;
88 using namespace ::com::sun::star;
89 using namespace ::com::sun::star::uno;
90 using namespace ::com::sun::star::ucb;
91 using namespace ::com::sun::star::io;
92 using namespace ::com::sun::star::resource;
93 using namespace ::com::sun::star::ui::dialogs;
95 #if defined(MAC)
96 #define FILTERMASK_ALL "****"
97 #elif defined(OW) || defined(MTF)
98 #define FILTERMASK_ALL "*"
99 #elif defined(PM2)
100 #define FILTERMASK_ALL ""
101 #else
102 #define FILTERMASK_ALL "*.*"
103 #endif
105 DBG_NAME( DialogWindow )
107 TYPEINIT1( DialogWindow, IDEBaseWindow );
109 DialogWindow::DialogWindow( Window* pParent, const ScriptDocument& rDocument, String aLibName, String aName,
110 const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xDialogModel )
111 :IDEBaseWindow( pParent, rDocument, aLibName, aName )
112 ,pUndoMgr(NULL)
114 InitSettings( TRUE, TRUE, TRUE );
116 pEditor = new DlgEditor( rDocument.getDocument() );
117 pEditor->SetWindow( this );
118 // set vba mode on DialogModel ( allows it to work in 100thmm instead of MAP_APPFONT )
119 if ( rDocument.getDocument().is() )
121 uno::Reference< script::XVBACompat > xDocVBAMode( rDocument.getLibraryContainer( E_SCRIPTS ), uno::UNO_QUERY );
122 uno::Reference< script::XVBACompat > xDialogModelVBAMode( xDialogModel, uno::UNO_QUERY );
123 if ( xDocVBAMode.is() && xDialogModelVBAMode.is() )
124 xDialogModelVBAMode->setVBACompatModeOn( xDocVBAMode->getVBACompatModeOn() );
126 pEditor->SetDialog( xDialogModel );
128 // Undo einrichten
129 pUndoMgr = new SfxUndoManager;
131 Link aDummyLink;
132 aOldNotifyUndoActionHdl = pEditor->GetModel()->GetNotifyUndoActionHdl();
133 pEditor->GetModel()->SetNotifyUndoActionHdl(
134 LINK(this, DialogWindow, NotifyUndoActionHdl));
136 SetHelpId( HID_BASICIDE_DIALOGWINDOW );
138 // set readonly mode for readonly libraries
139 ::rtl::OUString aOULibName( aLibName );
140 Reference< script::XLibraryContainer2 > xDlgLibContainer( GetDocument().getLibraryContainer( E_DIALOGS ), UNO_QUERY );
141 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) )
142 SetReadOnly( TRUE );
144 if ( rDocument.isDocument() && rDocument.isReadOnly() )
145 SetReadOnly( TRUE );
148 DialogWindow::~DialogWindow()
150 delete pEditor;
151 delete pUndoMgr;
154 void DialogWindow::LoseFocus()
156 if ( IsModified() )
157 StoreData();
159 Window::LoseFocus();
164 void DialogWindow::Paint( const Rectangle& rRect )
166 pEditor->Paint( rRect );
171 void DialogWindow::Resize()
173 if ( GetHScrollBar() && GetVScrollBar() ) {
174 pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
180 void DialogWindow::MouseButtonDown( const MouseEvent& rMEvt )
182 pEditor->MouseButtonDown( rMEvt );
184 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
185 if ( pBindings )
186 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
191 void DialogWindow::MouseButtonUp( const MouseEvent& rMEvt )
193 pEditor->MouseButtonUp( rMEvt );
194 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
195 if( (pEditor->GetMode() == DLGED_INSERT) && !pEditor->IsCreateOK() )
197 pEditor->SetMode( DLGED_SELECT );
198 if ( pBindings )
199 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
201 if ( pBindings )
203 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
204 pBindings->Invalidate( SID_DOC_MODIFIED );
205 pBindings->Invalidate( SID_SAVEDOC );
211 void DialogWindow::MouseMove( const MouseEvent& rMEvt )
213 pEditor->MouseMove( rMEvt );
218 void DialogWindow::KeyInput( const KeyEvent& rKEvt )
220 if( rKEvt.GetKeyCode() == KEY_BACKSPACE )
222 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
223 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
224 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
225 if( pDispatcher )
227 pDispatcher->Execute( SID_BACKSPACE );
230 else
232 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
233 if( pBindings && rKEvt.GetKeyCode() == KEY_TAB )
234 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
236 if( !pEditor->KeyInput( rKEvt ) )
238 if( !SfxViewShell::Current()->KeyInput( rKEvt ) )
239 Window::KeyInput( rKEvt );
244 void DialogWindow::Command( const CommandEvent& rCEvt )
246 if ( ( rCEvt.GetCommand() == COMMAND_WHEEL ) ||
247 ( rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL ) ||
248 ( rCEvt.GetCommand() == COMMAND_AUTOSCROLL ) )
250 HandleScrollCommand( rCEvt, GetHScrollBar(), GetVScrollBar() );
252 else if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
254 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
255 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
256 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
257 if ( pDispatcher )
259 SdrView* pView = GetView();
260 if( !rCEvt.IsMouseEvent() && pView->AreObjectsMarked() )
262 Rectangle aMarkedRect( pView->GetMarkedRect() );
263 Point MarkedCenter( aMarkedRect.Center() );
264 Point PosPixel( LogicToPixel( MarkedCenter ) );
265 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED), this, &PosPixel );
267 else
269 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED) );
274 else
275 IDEBaseWindow::Command( rCEvt );
281 IMPL_LINK( DialogWindow, NotifyUndoActionHdl, SfxUndoAction *, pUndoAction )
283 (void)pUndoAction;
285 // not working yet for unocontrols
287 if (pUndoAction)
289 pUndoMgr->AddUndoAction( pUndoAction );
290 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
291 if ( pBindings )
292 pBindings->Invalidate( SID_UNDO );
296 return 0;
301 void __EXPORT DialogWindow::DoInit()
303 GetHScrollBar()->Show();
304 GetVScrollBar()->Show();
305 pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
310 void __EXPORT DialogWindow::DoScroll( ScrollBar* pCurScrollBar )
312 pEditor->DoScroll( pCurScrollBar );
315 void __EXPORT DialogWindow::GetState( SfxItemSet& rSet )
317 SfxWhichIter aIter(rSet);
318 for ( USHORT nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
320 switch ( nWh )
322 case SID_PASTE:
324 if ( !IsPasteAllowed() )
325 rSet.DisableItem( nWh );
327 if ( IsReadOnly() )
328 rSet.DisableItem( nWh );
330 break;
331 case SID_COPY:
333 // any object selected?
334 if ( !pEditor->GetView()->AreObjectsMarked() )
335 rSet.DisableItem( nWh );
337 break;
338 case SID_CUT:
339 case SID_DELETE:
340 case SID_BACKSPACE:
342 // any object selected?
343 if ( !pEditor->GetView()->AreObjectsMarked() )
344 rSet.DisableItem( nWh );
346 if ( IsReadOnly() )
347 rSet.DisableItem( nWh );
349 break;
350 case SID_REDO:
352 if ( !pUndoMgr->GetUndoActionCount() )
353 rSet.DisableItem( nWh );
355 break;
357 // Nur Dialogfenster:
358 case SID_DIALOG_TESTMODE:
360 // ist die IDE noch aktiv?
361 if( IDE_DLL()->GetShell()->GetFrame() )
363 rSet.Put( SfxBoolItem( SID_DIALOG_TESTMODE,
364 (pEditor->GetMode() == DLGED_TEST) ? TRUE : FALSE) );
366 else
367 rSet.Put( SfxBoolItem( SID_DIALOG_TESTMODE,FALSE ));
369 break;
371 case SID_CHOOSE_CONTROLS:
373 if ( IsReadOnly() )
375 rSet.DisableItem( nWh );
377 else
379 SfxAllEnumItem aItem( SID_CHOOSE_CONTROLS );
380 if ( GetEditor()->GetMode() == DLGED_SELECT )
381 aItem.SetValue( SVX_SNAP_SELECT );
382 else
384 USHORT nObj;
385 switch( pEditor->GetInsertObj() )
387 case OBJ_DLG_PUSHBUTTON: nObj = SVX_SNAP_PUSHBUTTON; break;
388 case OBJ_DLG_RADIOBUTTON: nObj = SVX_SNAP_RADIOBUTTON; break;
389 case OBJ_DLG_CHECKBOX: nObj = SVX_SNAP_CHECKBOX; break;
390 case OBJ_DLG_LISTBOX: nObj = SVX_SNAP_LISTBOX; break;
391 case OBJ_DLG_COMBOBOX: nObj = SVX_SNAP_COMBOBOX; break;
392 case OBJ_DLG_GROUPBOX: nObj = SVX_SNAP_GROUPBOX; break;
393 case OBJ_DLG_EDIT: nObj = SVX_SNAP_EDIT; break;
394 case OBJ_DLG_FIXEDTEXT: nObj = SVX_SNAP_FIXEDTEXT; break;
395 case OBJ_DLG_IMAGECONTROL: nObj = SVX_SNAP_IMAGECONTROL; break;
396 case OBJ_DLG_PROGRESSBAR: nObj = SVX_SNAP_PROGRESSBAR; break;
397 case OBJ_DLG_HSCROLLBAR: nObj = SVX_SNAP_HSCROLLBAR; break;
398 case OBJ_DLG_VSCROLLBAR: nObj = SVX_SNAP_VSCROLLBAR; break;
399 case OBJ_DLG_HFIXEDLINE: nObj = SVX_SNAP_HFIXEDLINE; break;
400 case OBJ_DLG_VFIXEDLINE: nObj = SVX_SNAP_VFIXEDLINE; break;
401 case OBJ_DLG_DATEFIELD: nObj = SVX_SNAP_DATEFIELD; break;
402 case OBJ_DLG_TIMEFIELD: nObj = SVX_SNAP_TIMEFIELD; break;
403 case OBJ_DLG_NUMERICFIELD: nObj = SVX_SNAP_NUMERICFIELD; break;
404 case OBJ_DLG_CURRENCYFIELD: nObj = SVX_SNAP_CURRENCYFIELD; break;
405 case OBJ_DLG_FORMATTEDFIELD: nObj = SVX_SNAP_FORMATTEDFIELD; break;
406 case OBJ_DLG_PATTERNFIELD: nObj = SVX_SNAP_PATTERNFIELD; break;
407 case OBJ_DLG_FILECONTROL: nObj = SVX_SNAP_FILECONTROL; break;
408 case OBJ_DLG_TREECONTROL: nObj = SVX_SNAP_TREECONTROL; break;
409 default: nObj = 0;
411 #ifdef DBG_UTIL
412 if( !nObj )
414 DBG_WARNING( "SID_CHOOSE_CONTROLS: Unbekannt!" );
416 #endif
417 aItem.SetValue( nObj );
420 rSet.Put( aItem );
423 break;
425 case SID_SHOW_PROPERTYBROWSER:
427 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
428 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
429 if ( pViewFrame && !pViewFrame->HasChildWindow( SID_SHOW_PROPERTYBROWSER ) && !pEditor->GetView()->AreObjectsMarked() )
430 rSet.DisableItem( nWh );
432 if ( IsReadOnly() )
433 rSet.DisableItem( nWh );
435 break;
442 void __EXPORT DialogWindow::ExecuteCommand( SfxRequest& rReq )
444 switch ( rReq.GetSlot() )
446 case SID_CUT:
447 if ( !IsReadOnly() )
449 GetEditor()->Cut();
450 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
451 if ( pBindings )
452 pBindings->Invalidate( SID_DOC_MODIFIED );
454 break;
455 case SID_DELETE:
456 if ( !IsReadOnly() )
458 GetEditor()->Delete();
459 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
460 if ( pBindings )
461 pBindings->Invalidate( SID_DOC_MODIFIED );
463 break;
464 case SID_COPY:
465 GetEditor()->Copy();
466 break;
467 case SID_PASTE:
468 if ( !IsReadOnly() )
470 GetEditor()->Paste();
471 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
472 if ( pBindings )
473 pBindings->Invalidate( SID_DOC_MODIFIED );
475 break;
476 case SID_CHOOSE_CONTROLS:
478 const SfxItemSet* pArgs = rReq.GetArgs();
479 DBG_ASSERT( pArgs, "Nix Args" );
481 const SfxAllEnumItem& rItem = (SfxAllEnumItem&)pArgs->Get( SID_CHOOSE_CONTROLS );
482 switch( rItem.GetValue() )
484 case SVX_SNAP_PUSHBUTTON:
486 GetEditor()->SetMode( DLGED_INSERT );
487 GetEditor()->SetInsertObj( OBJ_DLG_PUSHBUTTON );
489 break;
490 case SVX_SNAP_RADIOBUTTON:
492 GetEditor()->SetMode( DLGED_INSERT );
493 GetEditor()->SetInsertObj( OBJ_DLG_RADIOBUTTON );
495 break;
496 case SVX_SNAP_CHECKBOX:
498 GetEditor()->SetMode( DLGED_INSERT );
499 GetEditor()->SetInsertObj( OBJ_DLG_CHECKBOX);
501 break;
502 case SVX_SNAP_LISTBOX:
504 GetEditor()->SetMode( DLGED_INSERT );
505 GetEditor()->SetInsertObj( OBJ_DLG_LISTBOX );
507 break;
508 case SVX_SNAP_COMBOBOX:
510 GetEditor()->SetMode( DLGED_INSERT );
511 GetEditor()->SetInsertObj( OBJ_DLG_COMBOBOX );
513 break;
514 case SVX_SNAP_GROUPBOX:
516 GetEditor()->SetMode( DLGED_INSERT );
517 GetEditor()->SetInsertObj( OBJ_DLG_GROUPBOX );
519 break;
520 case SVX_SNAP_EDIT:
522 GetEditor()->SetMode( DLGED_INSERT );
523 GetEditor()->SetInsertObj( OBJ_DLG_EDIT );
525 break;
526 case SVX_SNAP_FIXEDTEXT:
528 GetEditor()->SetMode( DLGED_INSERT );
529 GetEditor()->SetInsertObj( OBJ_DLG_FIXEDTEXT );
531 break;
532 case SVX_SNAP_IMAGECONTROL:
534 GetEditor()->SetMode( DLGED_INSERT );
535 GetEditor()->SetInsertObj( OBJ_DLG_IMAGECONTROL );
537 break;
538 case SVX_SNAP_PROGRESSBAR:
540 GetEditor()->SetMode( DLGED_INSERT );
541 GetEditor()->SetInsertObj( OBJ_DLG_PROGRESSBAR );
543 break;
544 case SVX_SNAP_HSCROLLBAR:
546 GetEditor()->SetMode( DLGED_INSERT );
547 GetEditor()->SetInsertObj( OBJ_DLG_HSCROLLBAR );
549 break;
550 case SVX_SNAP_VSCROLLBAR:
552 GetEditor()->SetMode( DLGED_INSERT );
553 GetEditor()->SetInsertObj( OBJ_DLG_VSCROLLBAR );
555 break;
556 case SVX_SNAP_HFIXEDLINE:
558 GetEditor()->SetMode( DLGED_INSERT );
559 GetEditor()->SetInsertObj( OBJ_DLG_HFIXEDLINE );
561 break;
562 case SVX_SNAP_VFIXEDLINE:
564 GetEditor()->SetMode( DLGED_INSERT );
565 GetEditor()->SetInsertObj( OBJ_DLG_VFIXEDLINE );
567 break;
568 case SVX_SNAP_DATEFIELD:
570 GetEditor()->SetMode( DLGED_INSERT );
571 GetEditor()->SetInsertObj( OBJ_DLG_DATEFIELD );
573 break;
574 case SVX_SNAP_TIMEFIELD:
576 GetEditor()->SetMode( DLGED_INSERT );
577 GetEditor()->SetInsertObj( OBJ_DLG_TIMEFIELD );
579 break;
580 case SVX_SNAP_NUMERICFIELD:
582 GetEditor()->SetMode( DLGED_INSERT );
583 GetEditor()->SetInsertObj( OBJ_DLG_NUMERICFIELD );
585 break;
586 case SVX_SNAP_CURRENCYFIELD:
588 GetEditor()->SetMode( DLGED_INSERT );
589 GetEditor()->SetInsertObj( OBJ_DLG_CURRENCYFIELD );
591 break;
592 case SVX_SNAP_FORMATTEDFIELD:
594 GetEditor()->SetMode( DLGED_INSERT );
595 GetEditor()->SetInsertObj( OBJ_DLG_FORMATTEDFIELD );
597 break;
598 case SVX_SNAP_PATTERNFIELD:
600 GetEditor()->SetMode( DLGED_INSERT );
601 GetEditor()->SetInsertObj( OBJ_DLG_PATTERNFIELD );
603 break;
604 case SVX_SNAP_FILECONTROL:
606 GetEditor()->SetMode( DLGED_INSERT );
607 GetEditor()->SetInsertObj( OBJ_DLG_FILECONTROL );
609 break;
610 case SVX_SNAP_TREECONTROL:
612 GetEditor()->SetMode( DLGED_INSERT );
613 GetEditor()->SetInsertObj( OBJ_DLG_TREECONTROL );
615 break;
617 case SVX_SNAP_SELECT:
619 GetEditor()->SetMode( DLGED_SELECT );
621 break;
624 if ( rReq.GetModifier() & KEY_MOD1 )
626 if ( GetEditor()->GetMode() == DLGED_INSERT )
627 GetEditor()->CreateDefaultObject();
630 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
631 if ( pBindings )
632 pBindings->Invalidate( SID_DOC_MODIFIED );
634 break;
636 case SID_DIALOG_TESTMODE:
638 DlgEdMode eOldMode = GetEditor()->GetMode();
639 GetEditor()->SetMode( DLGED_TEST );
640 GetEditor()->SetMode( eOldMode );
641 rReq.Done();
642 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
643 if ( pBindings )
644 pBindings->Invalidate( SID_DIALOG_TESTMODE );
645 return;
647 case SID_EXPORT_DIALOG:
648 SaveDialog();
649 break;
652 rReq.Done();
655 Reference< container::XNameContainer > DialogWindow::GetDialog() const
657 return pEditor->GetDialog();
660 BOOL DialogWindow::RenameDialog( const String& rNewName )
662 if ( !BasicIDE::RenameDialog( this, GetDocument(), GetLibName(), GetName(), rNewName ) )
663 return FALSE;
665 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
666 if ( pBindings )
667 pBindings->Invalidate( SID_DOC_MODIFIED );
669 return TRUE;
672 void DialogWindow::DisableBrowser()
674 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
675 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
676 SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow(SID_SHOW_PROPERTYBROWSER) : NULL;
677 if( pChildWin )
678 ((PropBrw*)(pChildWin->GetWindow()))->Update( NULL );
681 void DialogWindow::UpdateBrowser()
683 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
684 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
685 SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow(SID_SHOW_PROPERTYBROWSER) : NULL;
686 if( pChildWin )
687 ((PropBrw*)(pChildWin->GetWindow()))->Update( pIDEShell );
690 static ::rtl::OUString aResourceResolverPropName =
691 ::rtl::OUString::createFromAscii( "ResourceResolver" );
693 BOOL DialogWindow::SaveDialog()
695 DBG_CHKTHIS( DialogWindow, 0 );
696 BOOL bDone = FALSE;
698 Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
699 Reference < XFilePicker > xFP;
700 if( xMSF.is() )
702 Sequence <Any> aServiceType(1);
703 aServiceType[0] <<= TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
704 xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
705 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
708 Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
709 xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, sal_False);
710 Any aValue;
711 aValue <<= (sal_Bool) sal_True;
712 xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
714 if ( aCurPath.Len() )
715 xFP->setDisplayDirectory ( aCurPath );
717 xFP->setDefaultName( ::rtl::OUString( GetName() ) );
719 String aDialogStr( IDEResId( RID_STR_STDDIALOGNAME ) );
720 Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
721 xFltMgr->appendFilter( aDialogStr, String( RTL_CONSTASCII_USTRINGPARAM( "*.xdl" ) ) );
722 xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
723 xFltMgr->setCurrentFilter( aDialogStr );
725 if( xFP->execute() == RET_OK )
727 Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
728 aCurPath = aPaths[0];
730 // export dialog model to xml
731 Reference< container::XNameContainer > xDialogModel = GetDialog();
732 Reference< XComponentContext > xContext;
733 Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
734 OSL_ASSERT( xProps.is() );
735 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
736 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().getDocument() );
737 Reference< XInputStream > xInput( xISP->createInputStream() );
739 Reference< XSimpleFileAccess > xSFI( xMSF->createInstance
740 ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY );
742 Reference< XOutputStream > xOutput;
745 if( xSFI->exists( aCurPath ) )
746 xSFI->kill( aCurPath );
747 xOutput = xSFI->openFileWrite( aCurPath );
749 catch( Exception& )
752 if( xOutput.is() )
754 Sequence< sal_Int8 > bytes;
755 sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() );
756 for (;;)
758 if( nRead )
759 xOutput->writeBytes( bytes );
761 nRead = xInput->readBytes( bytes, 1024 );
762 if (! nRead)
763 break;
765 bDone = true;
767 // With resource?
768 Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
769 Reference< resource::XStringResourceResolver > xStringResourceResolver;
770 if( xDialogModelPropSet.is() )
774 Any aResourceResolver = xDialogModelPropSet->getPropertyValue( aResourceResolverPropName );
775 aResourceResolver >>= xStringResourceResolver;
777 catch( beans::UnknownPropertyException& )
781 bool bResource = false;
782 if( xStringResourceResolver.is() )
784 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
785 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
786 if( nLocaleCount > 0 )
787 bResource = true;
790 if( bResource )
792 INetURLObject aURLObj( aCurPath );
793 aURLObj.removeExtension();
794 ::rtl::OUString aDialogName( aURLObj.getName() );
795 aURLObj.removeSegment();
796 ::rtl::OUString aURL( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
797 sal_Bool bReadOnly = sal_False;
798 ::rtl::OUString aComment( ::rtl::OUString::createFromAscii( "# " ) );
799 aComment += aDialogName;
800 aComment += ::rtl::OUString::createFromAscii( " strings" );
801 Reference< task::XInteractionHandler > xDummyHandler;
803 // Remove old properties files in case of overwriting Dialog files
804 if( xSFI->isFolder( aURL ) )
806 Sequence< ::rtl::OUString > aContentSeq = xSFI->getFolderContents( aURL, false );
808 ::rtl::OUString aDialogName_( aDialogName );
809 aDialogName_ += ::rtl::OUString::createFromAscii( "_" );
810 sal_Int32 nCount = aContentSeq.getLength();
811 const ::rtl::OUString* pFiles = aContentSeq.getConstArray();
812 for( int i = 0 ; i < nCount ; i++ )
814 ::rtl::OUString aCompleteName = pFiles[i];
815 rtl::OUString aPureName;
816 rtl::OUString aExtension;
817 sal_Int32 iDot = aCompleteName.lastIndexOf( '.' );
818 sal_Int32 iSlash = aCompleteName.lastIndexOf( '/' );
819 if( iDot != -1 )
821 sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0;
822 aPureName = aCompleteName.copy( iCopyFrom, iDot-iCopyFrom );
823 aExtension = aCompleteName.copy( iDot + 1 );
826 if( aExtension.equalsAscii( "properties" ) ||
827 aExtension.equalsAscii( "default" ) )
829 if( aPureName.indexOf( aDialogName_ ) == 0 )
833 xSFI->kill( aCompleteName );
835 catch( uno::Exception& )
842 Reference< XStringResourceWithLocation > xStringResourceWithLocation =
843 StringResourceWithLocation::create( xContext, aURL, bReadOnly,
844 xStringResourceResolver->getDefaultLocale(), aDialogName, aComment, xDummyHandler );
846 // Add locales
847 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
848 const lang::Locale* pLocales = aLocaleSeq.getConstArray();
849 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
850 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ )
852 const lang::Locale& rLocale = pLocales[ iLocale ];
853 xStringResourceWithLocation->newLocale( rLocale );
856 Reference< XStringResourceManager > xTargetStringResourceManager( xStringResourceWithLocation, uno::UNO_QUERY );
858 LocalizationMgr::copyResourceForDialog( xDialogModel,
859 xStringResourceResolver, xTargetStringResourceManager );
861 xStringResourceWithLocation->store();
864 else
865 ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_COULDNTWRITE) ) ).Execute();
868 return bDone;
872 DlgEdModel* DialogWindow::GetModel() const
874 return pEditor ? pEditor->GetModel() : NULL;
877 DlgEdPage* DialogWindow::GetPage() const
879 return pEditor ? pEditor->GetPage() : NULL;
882 DlgEdView* DialogWindow::GetView() const
884 return pEditor ? pEditor->GetView() : NULL;
887 BOOL __EXPORT DialogWindow::IsModified()
889 return pEditor->IsModified();
892 SfxUndoManager* __EXPORT DialogWindow::GetUndoManager()
894 return pUndoMgr;
897 String DialogWindow::GetTitle()
899 return GetName();
902 BasicEntryDescriptor DialogWindow::CreateEntryDescriptor()
904 ScriptDocument aDocument( GetDocument() );
905 String aLibName( GetLibName() );
906 String aLibSubName;
907 LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
908 return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, GetName(), OBJ_TYPE_DIALOG );
911 void DialogWindow::SetReadOnly( BOOL b )
913 if ( pEditor )
915 if ( b )
916 pEditor->SetMode( DLGED_READONLY );
917 else
918 pEditor->SetMode( DLGED_SELECT );
922 BOOL DialogWindow::IsReadOnly()
924 BOOL bReadOnly = FALSE;
926 if ( pEditor && pEditor->GetMode() == DLGED_READONLY )
927 bReadOnly = TRUE;
929 return bReadOnly;
932 BOOL DialogWindow::IsPasteAllowed()
934 return pEditor ? pEditor->IsPasteAllowed() : FALSE;
937 void DialogWindow::StoreData()
939 if ( IsModified() )
943 Reference< container::XNameContainer > xLib = GetDocument().getLibrary( E_DIALOGS, GetLibName(), true );
945 if( xLib.is() )
947 Reference< container::XNameContainer > xDialogModel = pEditor->GetDialog();
949 if( xDialogModel.is() )
951 Reference< XComponentContext > xContext;
952 Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
953 OSL_ASSERT( xProps.is() );
954 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
955 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().getDocument() );
956 xLib->replaceByName( ::rtl::OUString( GetName() ), makeAny( xISP ) );
960 catch ( uno::Exception& )
962 DBG_UNHANDLED_EXCEPTION();
964 BasicIDE::MarkDocumentModified( GetDocument() );
965 pEditor->ClearModifyFlag();
969 void DialogWindow::Deactivating()
971 if ( IsModified() )
972 BasicIDE::MarkDocumentModified( GetDocument() );
975 void DialogWindow::PrintData( Printer* pPrinter )
977 pEditor->PrintData( pPrinter, CreateQualifiedName() );
980 void DialogWindow::DataChanged( const DataChangedEvent& rDCEvt )
982 if( (rDCEvt.GetType()==DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
984 InitSettings( TRUE, TRUE, TRUE );
985 Invalidate();
987 else
988 IDEBaseWindow::DataChanged( rDCEvt );
991 void DialogWindow::InitSettings(BOOL bFont,BOOL bForeground,BOOL bBackground)
993 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
994 if( bFont )
996 Font aFont;
997 aFont = rStyleSettings.GetFieldFont();
998 SetPointFont( aFont );
1001 if( bForeground || bFont )
1003 SetTextColor( rStyleSettings.GetFieldTextColor() );
1004 SetTextFillColor();
1007 if( bBackground )
1008 SetBackground( rStyleSettings.GetFieldColor() );
1011 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > DialogWindow::CreateAccessible()
1013 return (::com::sun::star::accessibility::XAccessible*) new AccessibleDialogWindow( this );