xref: /trunk/main/basctl/source/basicide/baside3.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basctl.hxx"
30 
31 //svdraw.hxx
32 //#define _SVDRAW_HXX ***
33 #define _SDR_NOITEMS
34 #define _SDR_NOTOUCH
35 #define _SDR_NOTRANSFORM
36 #define _SDR_NOOBJECTS
37 //#define _SDR_NOVIEWS ***
38 #define _SDR_NOVIEWMARKER
39 #define _SDR_NODRAGMETHODS
40 //#define _SDR_NOUNDO ***
41 #define _SDR_NOXOUTDEV
42 
43 #include <ide_pch.hxx>
44 
45 
46 #include <vector>
47 #include <basidesh.hrc>
48 #include <baside3.hxx>
49 #include <localizationmgr.hxx>
50 #include <accessibledialogwindow.hxx>
51 #include <dlged.hxx>
52 #include <dlgedmod.hxx>
53 #include <dlgedview.hxx>
54 #include <dlgeddef.hxx>
55 #include <propbrw.hxx>
56 
57 #include <basobj.hxx>
58 #include <iderdll.hxx>
59 #include <basidesh.hxx>
60 #include <idetemp.hxx>
61 #include <helpid.hrc>
62 #include <bastype2.hxx>
63 #include <svx/svdview.hxx>
64 #include <editeng/unolingu.hxx>
65 #include <tools/diagnose_ex.h>
66 #include <tools/urlobj.hxx>
67 #include <comphelper/processfactory.hxx>
68 #include <com/sun/star/container/XNameContainer.hpp>
69 #include <com/sun/star/beans/XPropertySet.hpp>
70 #include <xmlscript/xmldlg_imexp.hxx>
71 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
72 #include <com/sun/star/script/XLibraryContainer2.hpp>
73 #endif
74 #include <svtools/ehdl.hxx>
75 #include <svtools/langtab.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 
86 using namespace comphelper;
87 using namespace ::com::sun::star;
88 using namespace ::com::sun::star::uno;
89 using namespace ::com::sun::star::ucb;
90 using namespace ::com::sun::star::io;
91 using namespace ::com::sun::star::resource;
92 using namespace ::com::sun::star::ui::dialogs;
93 
94 #if defined(UNX)
95 #define FILTERMASK_ALL "*"
96 #elif defined(PM2)
97 #define FILTERMASK_ALL ""
98 #else
99 #define FILTERMASK_ALL "*.*"
100 #endif
101 
102 DBG_NAME( DialogWindow )
103 
104 TYPEINIT1( DialogWindow, IDEBaseWindow );
105 
106 DialogWindow::DialogWindow( Window* pParent, const ScriptDocument& rDocument, String aLibName, String aName,
107     const com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >& xDialogModel )
108         :IDEBaseWindow( pParent, rDocument, aLibName, aName )
109         ,pUndoMgr(NULL)
110 {
111     InitSettings( sal_True, sal_True, sal_True );
112 
113     pEditor = new DlgEditor();
114     pEditor->SetWindow( this );
115     pEditor->SetDialog( xDialogModel );
116 
117     // Undo einrichten
118     pUndoMgr = new SfxUndoManager;
119 
120     Link aDummyLink;
121     aOldNotifyUndoActionHdl = pEditor->GetModel()->GetNotifyUndoActionHdl();
122     pEditor->GetModel()->SetNotifyUndoActionHdl(
123         LINK(this, DialogWindow, NotifyUndoActionHdl));
124 
125     SetHelpId( HID_BASICIDE_DIALOGWINDOW );
126 
127     // set readonly mode for readonly libraries
128     ::rtl::OUString aOULibName( aLibName );
129     Reference< script::XLibraryContainer2 > xDlgLibContainer( GetDocument().getLibraryContainer( E_DIALOGS ), UNO_QUERY );
130     if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) )
131         SetReadOnly( sal_True );
132 
133     if ( rDocument.isDocument() && rDocument.isReadOnly() )
134         SetReadOnly( sal_True );
135 }
136 
137 DialogWindow::~DialogWindow()
138 {
139     delete pEditor;
140     delete pUndoMgr;
141 }
142 
143 void DialogWindow::LoseFocus()
144 {
145     if ( IsModified() )
146         StoreData();
147 
148     Window::LoseFocus();
149 }
150 
151 
152 
153 void DialogWindow::Paint( const Rectangle& rRect )
154 {
155     pEditor->Paint( rRect );
156 }
157 
158 
159 
160 void DialogWindow::Resize()
161 {
162     if ( GetHScrollBar() && GetVScrollBar() ) {
163         pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
164     }
165 }
166 
167 
168 
169 void DialogWindow::MouseButtonDown( const MouseEvent& rMEvt )
170 {
171     pEditor->MouseButtonDown( rMEvt );
172 
173     SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
174     if ( pBindings )
175         pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
176 }
177 
178 
179 
180 void DialogWindow::MouseButtonUp( const MouseEvent& rMEvt )
181 {
182     pEditor->MouseButtonUp( rMEvt );
183     SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
184     if( (pEditor->GetMode() == DLGED_INSERT) && !pEditor->IsCreateOK() )
185     {
186         pEditor->SetMode( DLGED_SELECT );
187         if ( pBindings )
188             pBindings->Invalidate( SID_CHOOSE_CONTROLS );
189     }
190     if ( pBindings )
191     {
192         pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
193         pBindings->Invalidate( SID_DOC_MODIFIED );
194         pBindings->Invalidate( SID_SAVEDOC );
195     }
196 }
197 
198 
199 
200 void DialogWindow::MouseMove( const MouseEvent& rMEvt )
201 {
202     pEditor->MouseMove( rMEvt );
203 }
204 
205 
206 
207 void DialogWindow::KeyInput( const KeyEvent& rKEvt )
208 {
209     if( rKEvt.GetKeyCode() == KEY_BACKSPACE )
210     {
211         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
212         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
213         SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
214         if( pDispatcher )
215         {
216             pDispatcher->Execute( SID_BACKSPACE );
217         }
218     }
219     else
220     {
221         SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
222         if( pBindings && rKEvt.GetKeyCode() == KEY_TAB )
223             pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
224 
225         if( !pEditor->KeyInput( rKEvt ) )
226         {
227             if( !SfxViewShell::Current()->KeyInput( rKEvt ) )
228                 Window::KeyInput( rKEvt );
229         }
230     }
231 }
232 
233 void DialogWindow::Command( const CommandEvent& rCEvt )
234 {
235     if ( ( rCEvt.GetCommand() == COMMAND_WHEEL ) ||
236             ( rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL ) ||
237             ( rCEvt.GetCommand() == COMMAND_AUTOSCROLL ) )
238     {
239         HandleScrollCommand( rCEvt, GetHScrollBar(), GetVScrollBar() );
240     }
241     else if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
242     {
243         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
244         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
245         SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
246         if ( pDispatcher )
247         {
248             SdrView* pView = GetView();
249             if( !rCEvt.IsMouseEvent() && pView->AreObjectsMarked() )
250             {
251                 Rectangle aMarkedRect( pView->GetMarkedRect() );
252                 Point MarkedCenter( aMarkedRect.Center() );
253                 Point PosPixel( LogicToPixel( MarkedCenter ) );
254                 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED), this, &PosPixel );
255             }
256             else
257             {
258                 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED) );
259             }
260 
261         }
262     }
263     else
264         IDEBaseWindow::Command( rCEvt );
265 }
266 
267 
268 
269 
270 IMPL_LINK( DialogWindow, NotifyUndoActionHdl, SfxUndoAction *, pUndoAction )
271 {
272     (void)pUndoAction;
273 
274     // not working yet for unocontrols
275     /*
276     if (pUndoAction)
277     {
278         pUndoMgr->AddUndoAction( pUndoAction );
279         SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
280         if ( pBindings )
281             pBindings->Invalidate( SID_UNDO );
282     }
283     */
284 
285     return 0;
286 }
287 
288 
289 
290 void __EXPORT DialogWindow::DoInit()
291 {
292     GetHScrollBar()->Show();
293     GetVScrollBar()->Show();
294     pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
295 }
296 
297 
298 
299 void __EXPORT DialogWindow::DoScroll( ScrollBar* pCurScrollBar )
300 {
301     pEditor->DoScroll( pCurScrollBar );
302 }
303 
304 void __EXPORT DialogWindow::GetState( SfxItemSet& rSet )
305 {
306     SfxWhichIter aIter(rSet);
307     for ( sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
308     {
309         switch ( nWh )
310         {
311             case SID_PASTE:
312             {
313                 if ( !IsPasteAllowed() )
314                     rSet.DisableItem( nWh );
315 
316                 if ( IsReadOnly() )
317                     rSet.DisableItem( nWh );
318             }
319             break;
320             case SID_COPY:
321             {
322                 // any object selected?
323                 if ( !pEditor->GetView()->AreObjectsMarked() )
324                     rSet.DisableItem( nWh );
325             }
326             break;
327             case SID_CUT:
328             case SID_DELETE:
329             case SID_BACKSPACE:
330             {
331                 // any object selected?
332                 if ( !pEditor->GetView()->AreObjectsMarked() )
333                     rSet.DisableItem( nWh );
334 
335                 if ( IsReadOnly() )
336                     rSet.DisableItem( nWh );
337             }
338             break;
339             case SID_REDO:
340             {
341                 if ( !pUndoMgr->GetUndoActionCount() )
342                     rSet.DisableItem( nWh );
343             }
344             break;
345 
346             // Nur Dialogfenster:
347             case SID_DIALOG_TESTMODE:
348             {
349                 // ist die IDE noch aktiv?
350                 if( IDE_DLL()->GetShell()->GetFrame() )
351                 {
352                     rSet.Put( SfxBoolItem( SID_DIALOG_TESTMODE,
353                               (pEditor->GetMode() == DLGED_TEST) ? sal_True : sal_False) );
354                 }
355                 else
356                     rSet.Put( SfxBoolItem( SID_DIALOG_TESTMODE,sal_False ));
357             }
358             break;
359 
360             case SID_CHOOSE_CONTROLS:
361             {
362                 if ( IsReadOnly() )
363                 {
364                     rSet.DisableItem( nWh );
365                 }
366                 else
367                 {
368                     SfxAllEnumItem aItem( SID_CHOOSE_CONTROLS );
369                     if ( GetEditor()->GetMode() == DLGED_SELECT )
370                         aItem.SetValue( SVX_SNAP_SELECT );
371                     else
372                     {
373                         sal_uInt16 nObj;
374                         switch( pEditor->GetInsertObj() )
375                         {
376                             case OBJ_DLG_PUSHBUTTON:        nObj = SVX_SNAP_PUSHBUTTON; break;
377                             case OBJ_DLG_RADIOBUTTON:       nObj = SVX_SNAP_RADIOBUTTON; break;
378                             case OBJ_DLG_CHECKBOX:          nObj = SVX_SNAP_CHECKBOX; break;
379                             case OBJ_DLG_LISTBOX:           nObj = SVX_SNAP_LISTBOX; break;
380                             case OBJ_DLG_COMBOBOX:          nObj = SVX_SNAP_COMBOBOX; break;
381                             case OBJ_DLG_GROUPBOX:          nObj = SVX_SNAP_GROUPBOX; break;
382                             case OBJ_DLG_EDIT:              nObj = SVX_SNAP_EDIT; break;
383                             case OBJ_DLG_FIXEDTEXT:         nObj = SVX_SNAP_FIXEDTEXT; break;
384                             case OBJ_DLG_IMAGECONTROL:      nObj = SVX_SNAP_IMAGECONTROL; break;
385                             case OBJ_DLG_PROGRESSBAR:       nObj = SVX_SNAP_PROGRESSBAR; break;
386                             case OBJ_DLG_HSCROLLBAR:        nObj = SVX_SNAP_HSCROLLBAR; break;
387                             case OBJ_DLG_VSCROLLBAR:        nObj = SVX_SNAP_VSCROLLBAR; break;
388                             case OBJ_DLG_HFIXEDLINE:        nObj = SVX_SNAP_HFIXEDLINE; break;
389                             case OBJ_DLG_VFIXEDLINE:        nObj = SVX_SNAP_VFIXEDLINE; break;
390                             case OBJ_DLG_DATEFIELD:         nObj = SVX_SNAP_DATEFIELD; break;
391                             case OBJ_DLG_TIMEFIELD:         nObj = SVX_SNAP_TIMEFIELD; break;
392                             case OBJ_DLG_NUMERICFIELD:      nObj = SVX_SNAP_NUMERICFIELD; break;
393                             case OBJ_DLG_CURRENCYFIELD:     nObj = SVX_SNAP_CURRENCYFIELD; break;
394                             case OBJ_DLG_FORMATTEDFIELD:    nObj = SVX_SNAP_FORMATTEDFIELD; break;
395                             case OBJ_DLG_PATTERNFIELD:      nObj = SVX_SNAP_PATTERNFIELD; break;
396                             case OBJ_DLG_FILECONTROL:       nObj = SVX_SNAP_FILECONTROL; break;
397                             case OBJ_DLG_TREECONTROL:       nObj = SVX_SNAP_TREECONTROL; break;
398                             default:                        nObj = 0;
399                         }
400 #ifdef DBG_UTIL
401                         if( !nObj )
402                         {
403                             DBG_WARNING( "SID_CHOOSE_CONTROLS: Unbekannt!" );
404                         }
405 #endif
406                         aItem.SetValue( nObj );
407                     }
408 
409                     rSet.Put( aItem );
410                 }
411             }
412             break;
413 
414             case SID_SHOW_PROPERTYBROWSER:
415             {
416                 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
417                 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
418                 if ( pViewFrame && !pViewFrame->HasChildWindow( SID_SHOW_PROPERTYBROWSER ) && !pEditor->GetView()->AreObjectsMarked() )
419                     rSet.DisableItem( nWh );
420 
421                 if ( IsReadOnly() )
422                     rSet.DisableItem( nWh );
423             }
424             break;
425         }
426     }
427 }
428 
429 
430 
431 void __EXPORT DialogWindow::ExecuteCommand( SfxRequest& rReq )
432 {
433     switch ( rReq.GetSlot() )
434     {
435         case SID_CUT:
436             if ( !IsReadOnly() )
437             {
438                 GetEditor()->Cut();
439                 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
440                 if ( pBindings )
441                     pBindings->Invalidate( SID_DOC_MODIFIED );
442             }
443             break;
444         case SID_DELETE:
445             if ( !IsReadOnly() )
446             {
447                 GetEditor()->Delete();
448                 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
449                 if ( pBindings )
450                     pBindings->Invalidate( SID_DOC_MODIFIED );
451             }
452             break;
453         case SID_COPY:
454             GetEditor()->Copy();
455             break;
456         case SID_PASTE:
457             if ( !IsReadOnly() )
458             {
459                 GetEditor()->Paste();
460                 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
461                 if ( pBindings )
462                     pBindings->Invalidate( SID_DOC_MODIFIED );
463             }
464             break;
465         case SID_CHOOSE_CONTROLS:
466         {
467             const SfxItemSet* pArgs = rReq.GetArgs();
468             DBG_ASSERT( pArgs, "Nix Args" );
469 
470             const SfxAllEnumItem& rItem = (SfxAllEnumItem&)pArgs->Get( SID_CHOOSE_CONTROLS );
471             switch( rItem.GetValue() )
472             {
473                 case SVX_SNAP_PUSHBUTTON:
474                 {
475                     GetEditor()->SetMode( DLGED_INSERT );
476                     GetEditor()->SetInsertObj( OBJ_DLG_PUSHBUTTON );
477                 }
478                 break;
479                 case SVX_SNAP_RADIOBUTTON:
480                 {
481                     GetEditor()->SetMode( DLGED_INSERT );
482                     GetEditor()->SetInsertObj( OBJ_DLG_RADIOBUTTON );
483                 }
484                 break;
485                 case SVX_SNAP_CHECKBOX:
486                 {
487                     GetEditor()->SetMode( DLGED_INSERT );
488                     GetEditor()->SetInsertObj( OBJ_DLG_CHECKBOX);
489                 }
490                 break;
491                 case SVX_SNAP_LISTBOX:
492                 {
493                     GetEditor()->SetMode( DLGED_INSERT );
494                     GetEditor()->SetInsertObj( OBJ_DLG_LISTBOX );
495                 }
496                 break;
497                 case SVX_SNAP_COMBOBOX:
498                 {
499                     GetEditor()->SetMode( DLGED_INSERT );
500                     GetEditor()->SetInsertObj( OBJ_DLG_COMBOBOX );
501                 }
502                 break;
503                 case SVX_SNAP_GROUPBOX:
504                 {
505                     GetEditor()->SetMode( DLGED_INSERT );
506                     GetEditor()->SetInsertObj( OBJ_DLG_GROUPBOX );
507                 }
508                 break;
509                 case SVX_SNAP_EDIT:
510                 {
511                     GetEditor()->SetMode( DLGED_INSERT );
512                     GetEditor()->SetInsertObj( OBJ_DLG_EDIT );
513                 }
514                 break;
515                 case SVX_SNAP_FIXEDTEXT:
516                 {
517                     GetEditor()->SetMode( DLGED_INSERT );
518                     GetEditor()->SetInsertObj( OBJ_DLG_FIXEDTEXT );
519                 }
520                 break;
521                 case SVX_SNAP_IMAGECONTROL:
522                 {
523                     GetEditor()->SetMode( DLGED_INSERT );
524                     GetEditor()->SetInsertObj( OBJ_DLG_IMAGECONTROL );
525                 }
526                 break;
527                 case SVX_SNAP_PROGRESSBAR:
528                 {
529                     GetEditor()->SetMode( DLGED_INSERT );
530                     GetEditor()->SetInsertObj( OBJ_DLG_PROGRESSBAR );
531                 }
532                 break;
533                 case SVX_SNAP_HSCROLLBAR:
534                 {
535                     GetEditor()->SetMode( DLGED_INSERT );
536                     GetEditor()->SetInsertObj( OBJ_DLG_HSCROLLBAR );
537                 }
538                 break;
539                 case SVX_SNAP_VSCROLLBAR:
540                 {
541                     GetEditor()->SetMode( DLGED_INSERT );
542                     GetEditor()->SetInsertObj( OBJ_DLG_VSCROLLBAR );
543                 }
544                 break;
545                 case SVX_SNAP_HFIXEDLINE:
546                 {
547                     GetEditor()->SetMode( DLGED_INSERT );
548                     GetEditor()->SetInsertObj( OBJ_DLG_HFIXEDLINE );
549                 }
550                 break;
551                 case SVX_SNAP_VFIXEDLINE:
552                 {
553                     GetEditor()->SetMode( DLGED_INSERT );
554                     GetEditor()->SetInsertObj( OBJ_DLG_VFIXEDLINE );
555                 }
556                 break;
557                 case SVX_SNAP_DATEFIELD:
558                 {
559                     GetEditor()->SetMode( DLGED_INSERT );
560                     GetEditor()->SetInsertObj( OBJ_DLG_DATEFIELD );
561                 }
562                 break;
563                 case SVX_SNAP_TIMEFIELD:
564                 {
565                     GetEditor()->SetMode( DLGED_INSERT );
566                     GetEditor()->SetInsertObj( OBJ_DLG_TIMEFIELD );
567                 }
568                 break;
569                 case SVX_SNAP_NUMERICFIELD:
570                 {
571                     GetEditor()->SetMode( DLGED_INSERT );
572                     GetEditor()->SetInsertObj( OBJ_DLG_NUMERICFIELD );
573                 }
574                 break;
575                 case SVX_SNAP_CURRENCYFIELD:
576                 {
577                     GetEditor()->SetMode( DLGED_INSERT );
578                     GetEditor()->SetInsertObj( OBJ_DLG_CURRENCYFIELD );
579                 }
580                 break;
581                 case SVX_SNAP_FORMATTEDFIELD:
582                 {
583                     GetEditor()->SetMode( DLGED_INSERT );
584                     GetEditor()->SetInsertObj( OBJ_DLG_FORMATTEDFIELD );
585                 }
586                 break;
587                 case SVX_SNAP_PATTERNFIELD:
588                 {
589                     GetEditor()->SetMode( DLGED_INSERT );
590                     GetEditor()->SetInsertObj( OBJ_DLG_PATTERNFIELD );
591                 }
592                 break;
593                 case SVX_SNAP_FILECONTROL:
594                 {
595                     GetEditor()->SetMode( DLGED_INSERT );
596                     GetEditor()->SetInsertObj( OBJ_DLG_FILECONTROL );
597                 }
598                 break;
599                 case SVX_SNAP_TREECONTROL:
600                 {
601                     GetEditor()->SetMode( DLGED_INSERT );
602                     GetEditor()->SetInsertObj( OBJ_DLG_TREECONTROL );
603                 }
604                 break;
605 
606                 case SVX_SNAP_SELECT:
607                 {
608                     GetEditor()->SetMode( DLGED_SELECT );
609                 }
610                 break;
611             }
612 
613             if ( rReq.GetModifier() & KEY_MOD1 )
614             {
615                 if ( GetEditor()->GetMode() == DLGED_INSERT )
616                     GetEditor()->CreateDefaultObject();
617             }
618 
619             SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
620             if ( pBindings )
621                 pBindings->Invalidate( SID_DOC_MODIFIED );
622         }
623         break;
624 
625         case SID_DIALOG_TESTMODE:
626         {
627             DlgEdMode eOldMode = GetEditor()->GetMode();
628             GetEditor()->SetMode( DLGED_TEST );
629             GetEditor()->SetMode( eOldMode );
630             rReq.Done();
631             SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
632             if ( pBindings )
633                 pBindings->Invalidate( SID_DIALOG_TESTMODE );
634             return;
635         }
636         case SID_EXPORT_DIALOG:
637             SaveDialog();
638             break;
639 
640         case SID_IMPORT_DIALOG:
641             ImportDialog();
642             break;
643     }
644 
645     rReq.Done();
646 }
647 
648 Reference< container::XNameContainer > DialogWindow::GetDialog() const
649 {
650     return pEditor->GetDialog();
651 }
652 
653 sal_Bool DialogWindow::RenameDialog( const String& rNewName )
654 {
655     if ( !BasicIDE::RenameDialog( this, GetDocument(), GetLibName(), GetName(), rNewName ) )
656         return sal_False;
657 
658     SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
659     if ( pBindings )
660         pBindings->Invalidate( SID_DOC_MODIFIED );
661 
662     return sal_True;
663 }
664 
665 void DialogWindow::DisableBrowser()
666 {
667     BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
668     SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
669     SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow(SID_SHOW_PROPERTYBROWSER) : NULL;
670     if( pChildWin )
671         ((PropBrw*)(pChildWin->GetWindow()))->Update( NULL );
672 }
673 
674 void DialogWindow::UpdateBrowser()
675 {
676     BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
677     SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
678     SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow(SID_SHOW_PROPERTYBROWSER) : NULL;
679     if( pChildWin )
680         ((PropBrw*)(pChildWin->GetWindow()))->Update( pIDEShell );
681 }
682 
683 static ::rtl::OUString aResourceResolverPropName =
684     ::rtl::OUString::createFromAscii( "ResourceResolver" );
685 
686 sal_Bool DialogWindow::SaveDialog()
687 {
688     DBG_CHKTHIS( DialogWindow, 0 );
689     sal_Bool bDone = sal_False;
690 
691     Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
692     Reference < XFilePicker > xFP;
693     if( xMSF.is() )
694     {
695         Sequence <Any> aServiceType(1);
696         aServiceType[0] <<= TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
697         xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
698                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
699     }
700 
701     Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
702     xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, sal_False);
703     Any aValue;
704     aValue <<= (sal_Bool) sal_True;
705     xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
706 
707     if ( aCurPath.Len() )
708         xFP->setDisplayDirectory ( aCurPath );
709 
710     xFP->setDefaultName( ::rtl::OUString( GetName() ) );
711 
712     String aDialogStr( IDEResId( RID_STR_STDDIALOGNAME ) );
713     Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
714     xFltMgr->appendFilter( aDialogStr, String( RTL_CONSTASCII_USTRINGPARAM( "*.xdl" ) ) );
715     xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
716     xFltMgr->setCurrentFilter( aDialogStr );
717 
718     if( xFP->execute() == RET_OK )
719     {
720         Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
721         aCurPath = aPaths[0];
722 
723         // export dialog model to xml
724         Reference< container::XNameContainer > xDialogModel = GetDialog();
725         Reference< XComponentContext > xContext;
726         Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
727         OSL_ASSERT( xProps.is() );
728         OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
729         Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext );
730         Reference< XInputStream > xInput( xISP->createInputStream() );
731 
732         Reference< XSimpleFileAccess > xSFI( xMSF->createInstance
733             ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY );
734 
735         Reference< XOutputStream > xOutput;
736         try
737         {
738             if( xSFI->exists( aCurPath ) )
739                 xSFI->kill( aCurPath );
740             xOutput = xSFI->openFileWrite( aCurPath );
741         }
742         catch( Exception& )
743         {}
744 
745         if( xOutput.is() )
746         {
747             Sequence< sal_Int8 > bytes;
748             sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() );
749             for (;;)
750             {
751                 if( nRead )
752                     xOutput->writeBytes( bytes );
753 
754                 nRead = xInput->readBytes( bytes, 1024 );
755                 if (! nRead)
756                     break;
757             }
758             bDone = true;
759 
760             // With resource?
761             Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
762             Reference< resource::XStringResourceResolver > xStringResourceResolver;
763             if( xDialogModelPropSet.is() )
764             {
765                 try
766                 {
767                     Any aResourceResolver = xDialogModelPropSet->getPropertyValue( aResourceResolverPropName );
768                     aResourceResolver >>= xStringResourceResolver;
769                 }
770                 catch( beans::UnknownPropertyException& )
771                 {}
772             }
773 
774             bool bResource = false;
775             if( xStringResourceResolver.is() )
776             {
777                 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
778                 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
779                 if( nLocaleCount > 0 )
780                     bResource = true;
781             }
782 
783             if( bResource )
784             {
785                 INetURLObject aURLObj( aCurPath );
786                 aURLObj.removeExtension();
787                 ::rtl::OUString aDialogName( aURLObj.getName() );
788                 aURLObj.removeSegment();
789                 ::rtl::OUString aURL( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
790                 sal_Bool bReadOnly = sal_False;
791                 ::rtl::OUString aComment( ::rtl::OUString::createFromAscii( "# " ) );
792                 aComment += aDialogName;
793                 aComment += ::rtl::OUString::createFromAscii( " strings" );
794                 Reference< task::XInteractionHandler > xDummyHandler;
795 
796                 // Remove old properties files in case of overwriting Dialog files
797                 if( xSFI->isFolder( aURL ) )
798                 {
799                     Sequence< ::rtl::OUString > aContentSeq = xSFI->getFolderContents( aURL, false );
800 
801                     ::rtl::OUString aDialogName_( aDialogName );
802                     aDialogName_ += ::rtl::OUString::createFromAscii( "_" );
803                     sal_Int32 nCount = aContentSeq.getLength();
804                     const ::rtl::OUString* pFiles = aContentSeq.getConstArray();
805                     for( int i = 0 ; i < nCount ; i++ )
806                     {
807                         ::rtl::OUString aCompleteName = pFiles[i];
808                         rtl::OUString aPureName;
809                         rtl::OUString aExtension;
810                         sal_Int32 iDot = aCompleteName.lastIndexOf( '.' );
811                         sal_Int32 iSlash = aCompleteName.lastIndexOf( '/' );
812                         if( iDot != -1 )
813                         {
814                             sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0;
815                             aPureName = aCompleteName.copy( iCopyFrom, iDot-iCopyFrom );
816                             aExtension = aCompleteName.copy( iDot + 1 );
817                         }
818 
819                         if( aExtension.equalsAscii( "properties" ) ||
820                             aExtension.equalsAscii( "default" ) )
821                         {
822                             if( aPureName.indexOf( aDialogName_ ) == 0 )
823                             {
824                                 try
825                                 {
826                                     xSFI->kill( aCompleteName );
827                                 }
828                                 catch( uno::Exception& )
829                                 {}
830                             }
831                         }
832                     }
833                 }
834 
835                 Reference< XStringResourceWithLocation > xStringResourceWithLocation =
836                     StringResourceWithLocation::create( xContext, aURL, bReadOnly,
837                         xStringResourceResolver->getDefaultLocale(), aDialogName, aComment, xDummyHandler );
838 
839                 // Add locales
840                 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
841                 const lang::Locale* pLocales = aLocaleSeq.getConstArray();
842                 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
843                 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ )
844                 {
845                     const lang::Locale& rLocale = pLocales[ iLocale ];
846                     xStringResourceWithLocation->newLocale( rLocale );
847                 }
848 
849                 Reference< XStringResourceManager > xTargetStringResourceManager( xStringResourceWithLocation, uno::UNO_QUERY );
850 
851                 LocalizationMgr::copyResourceForDialog( xDialogModel,
852                     xStringResourceResolver, xTargetStringResourceManager );
853 
854                 xStringResourceWithLocation->store();
855             }
856         }
857         else
858             ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_COULDNTWRITE) ) ).Execute();
859     }
860 
861     return bDone;
862 }
863 
864 extern bool localesAreEqual( const ::com::sun::star::lang::Locale& rLocaleLeft,
865                              const ::com::sun::star::lang::Locale& rLocaleRight );
866 
867 std::vector< lang::Locale > implGetLanguagesOnlyContainedInFirstSeq
868     ( Sequence< lang::Locale > aFirstSeq, Sequence< lang::Locale > aSecondSeq )
869 {
870     std::vector< lang::Locale > avRet;
871 
872     const lang::Locale* pFirst = aFirstSeq.getConstArray();
873     const lang::Locale* pSecond = aSecondSeq.getConstArray();
874     sal_Int32 nFirstCount = aFirstSeq.getLength();
875     sal_Int32 nSecondCount = aSecondSeq.getLength();
876 
877     for( sal_Int32 iFirst = 0 ; iFirst < nFirstCount ; iFirst++ )
878     {
879         const lang::Locale& rFirstLocale = pFirst[ iFirst ];
880 
881         bool bAlsoContainedInSecondSeq = false;
882         for( sal_Int32 iSecond = 0 ; iSecond < nSecondCount ; iSecond++ )
883         {
884             const lang::Locale& rSecondLocale = pSecond[ iSecond ];
885 
886             bool bMatch = localesAreEqual( rFirstLocale, rSecondLocale );
887             if( bMatch )
888             {
889                 bAlsoContainedInSecondSeq = true;
890                 break;
891             }
892         }
893 
894         if( !bAlsoContainedInSecondSeq )
895             avRet.push_back( rFirstLocale );
896     }
897 
898     return avRet;
899 }
900 
901 
902 class NameClashQueryBox : public MessBox
903 {
904 public:
905     NameClashQueryBox( Window* pParent,
906         const XubString& rTitle, const XubString& rMessage );
907 };
908 
909 NameClashQueryBox::NameClashQueryBox( Window* pParent,
910     const XubString& rTitle, const XubString& rMessage )
911         : MessBox( pParent, 0, rTitle, rMessage )
912 {
913     if ( rTitle.Len() )
914         SetText( rTitle );
915 
916     maMessText = rMessage;
917 
918     AddButton( String( IDEResId( RID_STR_DLGIMP_CLASH_RENAME ) ), RET_YES,
919         BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_OKBUTTON | BUTTONDIALOG_FOCUSBUTTON );
920     AddButton( String( IDEResId( RID_STR_DLGIMP_CLASH_REPLACE ) ), RET_NO, 0 );
921     AddButton( BUTTON_CANCEL, RET_CANCEL, BUTTONDIALOG_CANCELBUTTON );
922 
923     SetImage( GetSettings().GetStyleSettings().GetHighContrastMode() ?
924         QueryBox::GetStandardImageHC() : QueryBox::GetStandardImage() );
925 }
926 
927 
928 class LanguageMismatchQueryBox : public MessBox
929 {
930 public:
931     LanguageMismatchQueryBox( Window* pParent,
932         const XubString& rTitle, const XubString& rMessage );
933 };
934 
935 LanguageMismatchQueryBox::LanguageMismatchQueryBox( Window* pParent,
936     const XubString& rTitle, const XubString& rMessage )
937         : MessBox( pParent, 0, rTitle, rMessage )
938 {
939     if ( rTitle.Len() )
940         SetText( rTitle );
941 
942     maMessText = rMessage;
943     AddButton( String( IDEResId( RID_STR_DLGIMP_MISMATCH_ADD ) ), RET_YES,
944         BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_OKBUTTON | BUTTONDIALOG_FOCUSBUTTON );
945     AddButton( String( IDEResId( RID_STR_DLGIMP_MISMATCH_OMIT ) ), RET_NO, 0 );
946     AddButton( BUTTON_CANCEL, RET_CANCEL, BUTTONDIALOG_CANCELBUTTON );
947     AddButton( BUTTON_HELP, BUTTONID_HELP, BUTTONDIALOG_HELPBUTTON, 4 );
948 
949     SetImage( GetSettings().GetStyleSettings().GetHighContrastMode() ?
950         QueryBox::GetStandardImageHC() : QueryBox::GetStandardImage() );
951 }
952 
953 sal_Bool implImportDialog( Window* pWin, const String& rCurPath, const ScriptDocument& rDocument, const String& aLibName )
954 {
955     sal_Bool bDone = sal_False;
956 
957     Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
958     Reference < XFilePicker > xFP;
959     if( xMSF.is() )
960     {
961         Sequence <Any> aServiceType(1);
962         aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE;
963         xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments(
964                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY );
965     }
966 
967     Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
968     xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, sal_False);
969     Any aValue;
970     aValue <<= (sal_Bool) sal_True;
971     xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
972 
973     String aCurPath( rCurPath );
974     if ( aCurPath.Len() )
975         xFP->setDisplayDirectory ( aCurPath );
976 
977     String aDialogStr( IDEResId( RID_STR_STDDIALOGNAME ) );
978     Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY);
979     xFltMgr->appendFilter( aDialogStr, String( RTL_CONSTASCII_USTRINGPARAM( "*.xdl" ) ) );
980     xFltMgr->appendFilter( String( IDEResId( RID_STR_FILTER_ALLFILES ) ), String( RTL_CONSTASCII_USTRINGPARAM( FILTERMASK_ALL ) ) );
981     xFltMgr->setCurrentFilter( aDialogStr );
982 
983     if( xFP->execute() == RET_OK )
984     {
985         Sequence< ::rtl::OUString > aPaths = xFP->getFiles();
986         aCurPath = aPaths[0];
987 
988         ::rtl::OUString aBasePath;
989         ::rtl::OUString aOUCurPath( aCurPath );
990         sal_Int32 iSlash = aOUCurPath.lastIndexOf( '/' );
991         if( iSlash != -1 )
992             aBasePath = aOUCurPath.copy( 0, iSlash + 1 );
993 
994         try
995         {
996             // create dialog model
997             Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
998                 ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY_THROW );
999 
1000             Reference< XSimpleFileAccess > xSFI( xMSF->createInstance
1001                 ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY_THROW );
1002 
1003             Reference< XInputStream > xInput;
1004             if( xSFI->exists( aCurPath ) )
1005                 xInput = xSFI->openFileRead( aCurPath );
1006 
1007             Reference< XComponentContext > xContext;
1008             Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
1009             OSL_ASSERT( xProps.is() );
1010             OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
1011             ::xmlscript::importDialogModel( xInput, xDialogModel, xContext );
1012 
1013             String aXmlDlgName;
1014             Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
1015             if( xDialogModelPropSet.is() )
1016             {
1017                 try
1018                 {
1019                     Any aXmlDialogNameAny = xDialogModelPropSet->getPropertyValue( DLGED_PROP_NAME );
1020                     ::rtl::OUString aOUXmlDialogName;
1021                     aXmlDialogNameAny >>= aOUXmlDialogName;
1022                     aXmlDlgName = aOUXmlDialogName;
1023                 }
1024                 catch( beans::UnknownPropertyException& )
1025                 {}
1026             }
1027             bool bValidName = (aXmlDlgName.Len() != 0);
1028             OSL_ASSERT( bValidName );
1029             if( !bValidName )
1030                 return bDone;
1031 
1032             bool bDialogAlreadyExists = rDocument.hasDialog( aLibName, aXmlDlgName );
1033 
1034             String aNewDlgName = aXmlDlgName;
1035             enum NameClashMode
1036             {
1037                 NO_CLASH,
1038                 CLASH_OVERWRITE_DIALOG,
1039                 CLASH_RENAME_DIALOG,
1040             };
1041             NameClashMode eNameClashMode = NO_CLASH;
1042             if( bDialogAlreadyExists )
1043             {
1044                 String aQueryBoxTitle( IDEResId( RID_STR_DLGIMP_CLASH_TITLE ) );
1045                 String aQueryBoxText( IDEResId( RID_STR_DLGIMP_CLASH_TEXT ) );
1046                 aQueryBoxText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "$(ARG1)" ) ), aXmlDlgName );
1047 
1048                 NameClashQueryBox aQueryBox( pWin, aQueryBoxTitle, aQueryBoxText );
1049                 sal_uInt16 nRet = aQueryBox.Execute();
1050                 if( RET_YES == nRet )
1051                 {
1052                     // RET_YES == Rename, see NameClashQueryBox::NameClashQueryBox
1053                     eNameClashMode = CLASH_RENAME_DIALOG;
1054 
1055                     aNewDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
1056                 }
1057                 else if( RET_NO == nRet )
1058                 {
1059                     // RET_NO == Replace, see NameClashQueryBox::NameClashQueryBox
1060                     eNameClashMode = CLASH_OVERWRITE_DIALOG;
1061                 }
1062                 else if( RET_CANCEL == nRet )
1063                 {
1064                     return bDone;
1065                 }
1066             }
1067 
1068             BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
1069             if( pIDEShell == NULL )
1070             {
1071                 OSL_ASSERT( pIDEShell != NULL );
1072                 return bDone;
1073             }
1074 
1075             // Resource?
1076             ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
1077             Reference< task::XInteractionHandler > xDummyHandler;
1078             bool bReadOnly = true;
1079             Reference< XStringResourceWithLocation > xImportStringResource =
1080                 StringResourceWithLocation::create( xContext, aBasePath, bReadOnly,
1081                 aLocale, aXmlDlgName, ::rtl::OUString(), xDummyHandler );
1082 
1083             Sequence< lang::Locale > aImportLocaleSeq = xImportStringResource->getLocales();
1084             sal_Int32 nImportLocaleCount = aImportLocaleSeq.getLength();
1085 
1086             Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, sal_True ) );
1087             Reference< resource::XStringResourceManager > xLibStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
1088             sal_Int32 nLibLocaleCount = 0;
1089             Sequence< lang::Locale > aLibLocaleSeq;
1090             if( xLibStringResourceManager.is() )
1091             {
1092                 aLibLocaleSeq = xLibStringResourceManager->getLocales();
1093                 nLibLocaleCount = aLibLocaleSeq.getLength();
1094             }
1095 
1096             // Check language matches
1097             std::vector< lang::Locale > aOnlyInImportLanguages =
1098                 implGetLanguagesOnlyContainedInFirstSeq( aImportLocaleSeq, aLibLocaleSeq );
1099             int nOnlyInImportLanguageCount = aOnlyInImportLanguages.size();
1100 
1101             // For now: Keep languages from lib
1102             bool bLibLocalized = (nLibLocaleCount > 0);
1103             bool bImportLocalized = (nImportLocaleCount > 0);
1104 
1105             bool bAddDialogLanguagesToLib = false;
1106             if( nOnlyInImportLanguageCount > 0 )
1107             {
1108                 String aQueryBoxTitle( IDEResId( RID_STR_DLGIMP_MISMATCH_TITLE ) );
1109                 String aQueryBoxText( IDEResId( RID_STR_DLGIMP_MISMATCH_TEXT ) );
1110                 LanguageMismatchQueryBox aQueryBox( pWin, aQueryBoxTitle, aQueryBoxText );
1111                 sal_uInt16 nRet = aQueryBox.Execute();
1112                 if( RET_YES == nRet )
1113                 {
1114                     // RET_YES == Add, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
1115                     bAddDialogLanguagesToLib = true;
1116                 }
1117                 // RET_NO == Omit, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
1118                 // -> nothing to do here
1119                 //else if( RET_NO == nRet )
1120                 //{
1121                 //}
1122                 else if( RET_CANCEL == nRet )
1123                 {
1124                     return bDone;
1125                 }
1126             }
1127 
1128             if( bImportLocalized )
1129             {
1130                 bool bCopyResourcesForDialog = true;
1131                 if( bAddDialogLanguagesToLib )
1132                 {
1133                     LocalizationMgr* pCurMgr = pIDEShell->GetCurLocalizationMgr();
1134 
1135                     lang::Locale aFirstLocale;
1136                     aFirstLocale = aOnlyInImportLanguages[0];
1137                     if( nOnlyInImportLanguageCount > 1 )
1138                     {
1139                         // Check if import default belongs to only import languages and use it then
1140                         lang::Locale aImportDefaultLocale = xImportStringResource->getDefaultLocale();
1141                         lang::Locale aTmpLocale;
1142                         for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
1143                         {
1144                             aTmpLocale = aOnlyInImportLanguages[i];
1145                             if( localesAreEqual( aImportDefaultLocale, aTmpLocale ) )
1146                             {
1147                                 aFirstLocale = aImportDefaultLocale;
1148                                 break;
1149                             }
1150                         }
1151                     }
1152 
1153                     Sequence< lang::Locale > aFirstLocaleSeq( 1 );
1154                     aFirstLocaleSeq[0] = aFirstLocale;
1155                     pCurMgr->handleAddLocales( aFirstLocaleSeq );
1156 
1157                     if( nOnlyInImportLanguageCount > 1 )
1158                     {
1159                         Sequence< lang::Locale > aRemainingLocaleSeq( nOnlyInImportLanguageCount - 1 );
1160                         lang::Locale aTmpLocale;
1161                         int iSeq = 0;
1162                         for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
1163                         {
1164                             aTmpLocale = aOnlyInImportLanguages[i];
1165                             if( !localesAreEqual( aFirstLocale, aTmpLocale ) )
1166                                 aRemainingLocaleSeq[iSeq++] = aTmpLocale;
1167                         }
1168                         pCurMgr->handleAddLocales( aRemainingLocaleSeq );
1169                     }
1170                 }
1171                 else if( !bLibLocalized )
1172                 {
1173                     Reference< resource::XStringResourceManager > xImportStringResourceManager( xImportStringResource, UNO_QUERY );
1174                     LocalizationMgr::resetResourceForDialog( xDialogModel, xImportStringResourceManager );
1175                     bCopyResourcesForDialog = false;
1176                 }
1177 
1178                 if( bCopyResourcesForDialog )
1179                 {
1180                     Reference< resource::XStringResourceResolver > xImportStringResourceResolver( xImportStringResource, UNO_QUERY );
1181                     LocalizationMgr::copyResourceForDroppedDialog( xDialogModel, aXmlDlgName,
1182                         xLibStringResourceManager, xImportStringResourceResolver );
1183                 }
1184             }
1185             else if( bLibLocalized )
1186             {
1187                 LocalizationMgr::setResourceIDsForDialog( xDialogModel, xLibStringResourceManager );
1188             }
1189 
1190 
1191             LocalizationMgr::setStringResourceAtDialog( rDocument, aLibName, aNewDlgName, xDialogModel );
1192 
1193             if( eNameClashMode == CLASH_OVERWRITE_DIALOG )
1194             {
1195                 if ( BasicIDE::RemoveDialog( rDocument, aLibName, aNewDlgName ) )
1196                 {
1197                     IDEBaseWindow* pDlgWin = pIDEShell->FindDlgWin( rDocument, aLibName, aNewDlgName, sal_False, sal_True );
1198                     if( pDlgWin != NULL )
1199                         pIDEShell->RemoveWindow( pDlgWin, sal_True );
1200                     BasicIDE::MarkDocumentModified( rDocument );
1201                 }
1202                 else
1203                 {
1204                     // TODO: Assertion?
1205                     return bDone;
1206                 }
1207             }
1208 
1209             if( eNameClashMode == CLASH_RENAME_DIALOG )
1210             {
1211                 bool bRenamed = false;
1212                 if( xDialogModelPropSet.is() )
1213                 {
1214                     try
1215                     {
1216                         Any aXmlDialogNameAny;
1217                         aXmlDialogNameAny <<= ::rtl::OUString( aNewDlgName );
1218                         xDialogModelPropSet->setPropertyValue( DLGED_PROP_NAME, aXmlDialogNameAny );
1219                         bRenamed = true;
1220                     }
1221                     catch( beans::UnknownPropertyException& )
1222                     {}
1223                 }
1224 
1225 
1226                 if( bRenamed )
1227                 {
1228                     LocalizationMgr::renameStringResourceIDs( rDocument, aLibName, aNewDlgName, xDialogModel );
1229                 }
1230                 else
1231                 {
1232                     // TODO: Assertion?
1233                     return bDone;
1234                 }
1235             }
1236 
1237             Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext );
1238             bool bSuccess = rDocument.insertDialog( aLibName, aNewDlgName, xISP );
1239             if( bSuccess )
1240             {
1241                 DialogWindow* pNewDlgWin = pIDEShell->CreateDlgWin( rDocument, aLibName, aNewDlgName );
1242                 pIDEShell->SetCurWindow( pNewDlgWin, sal_True );
1243             }
1244 
1245             bDone = sal_True;
1246         }
1247         catch( Exception& )
1248         {}
1249     }
1250 
1251     return bDone;
1252 }
1253 
1254 sal_Bool DialogWindow::ImportDialog()
1255 {
1256     DBG_CHKTHIS( DialogWindow, 0 );
1257 
1258     const ScriptDocument& rDocument = GetDocument();
1259     String aLibName = GetLibName();
1260     sal_Bool bRet = implImportDialog( this, aCurPath, rDocument, aLibName );
1261     return bRet;
1262 }
1263 
1264 DlgEdModel* DialogWindow::GetModel() const
1265 {
1266     return pEditor ? pEditor->GetModel() : NULL;
1267 }
1268 
1269 DlgEdPage* DialogWindow::GetPage() const
1270 {
1271     return pEditor ? pEditor->GetPage() : NULL;
1272 }
1273 
1274 DlgEdView* DialogWindow::GetView() const
1275 {
1276     return pEditor ? pEditor->GetView() : NULL;
1277 }
1278 
1279 sal_Bool __EXPORT DialogWindow::IsModified()
1280 {
1281     return pEditor->IsModified();
1282 }
1283 
1284 ::svl::IUndoManager* __EXPORT DialogWindow::GetUndoManager()
1285 {
1286     return pUndoMgr;
1287 }
1288 
1289 String DialogWindow::GetTitle()
1290 {
1291     return GetName();
1292 }
1293 
1294 BasicEntryDescriptor DialogWindow::CreateEntryDescriptor()
1295 {
1296     ScriptDocument aDocument( GetDocument() );
1297     String aLibName( GetLibName() );
1298     String aLibSubName;
1299     LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
1300     return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, GetName(), OBJ_TYPE_DIALOG );
1301 }
1302 
1303 void DialogWindow::SetReadOnly( sal_Bool b )
1304 {
1305     if ( pEditor )
1306     {
1307         if ( b )
1308             pEditor->SetMode( DLGED_READONLY );
1309         else
1310             pEditor->SetMode( DLGED_SELECT );
1311     }
1312 }
1313 
1314 sal_Bool DialogWindow::IsReadOnly()
1315 {
1316     sal_Bool bReadOnly = sal_False;
1317 
1318     if ( pEditor && pEditor->GetMode() == DLGED_READONLY )
1319         bReadOnly = sal_True;
1320 
1321     return bReadOnly;
1322 }
1323 
1324 sal_Bool DialogWindow::IsPasteAllowed()
1325 {
1326     return pEditor ? pEditor->IsPasteAllowed() : sal_False;
1327 }
1328 
1329 void DialogWindow::StoreData()
1330 {
1331     if ( IsModified() )
1332     {
1333         try
1334         {
1335             Reference< container::XNameContainer > xLib = GetDocument().getLibrary( E_DIALOGS, GetLibName(), true );
1336 
1337             if( xLib.is() )
1338             {
1339                 Reference< container::XNameContainer > xDialogModel = pEditor->GetDialog();
1340 
1341                 if( xDialogModel.is() )
1342                 {
1343                     Reference< XComponentContext > xContext;
1344                     Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
1345                     OSL_ASSERT( xProps.is() );
1346                     OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
1347                     Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext );
1348                     xLib->replaceByName( ::rtl::OUString( GetName() ), makeAny( xISP ) );
1349                 }
1350             }
1351         }
1352         catch ( uno::Exception& )
1353         {
1354             DBG_UNHANDLED_EXCEPTION();
1355         }
1356         BasicIDE::MarkDocumentModified( GetDocument() );
1357         pEditor->ClearModifyFlag();
1358     }
1359 }
1360 
1361 void DialogWindow::Deactivating()
1362 {
1363     if ( IsModified() )
1364         BasicIDE::MarkDocumentModified( GetDocument() );
1365 }
1366 
1367 sal_Int32 DialogWindow::countPages( Printer* pPrinter )
1368 {
1369     return pEditor->countPages( pPrinter );
1370 }
1371 
1372 void DialogWindow::printPage( sal_Int32 nPage, Printer* pPrinter )
1373 {
1374     pEditor->printPage( nPage, pPrinter, CreateQualifiedName() );
1375 }
1376 
1377 void DialogWindow::DataChanged( const DataChangedEvent& rDCEvt )
1378 {
1379     if( (rDCEvt.GetType()==DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1380     {
1381         InitSettings( sal_True, sal_True, sal_True );
1382         Invalidate();
1383     }
1384     else
1385         IDEBaseWindow::DataChanged( rDCEvt );
1386 }
1387 
1388 void DialogWindow::InitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)
1389 {
1390     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1391     if( bFont )
1392     {
1393         Font aFont;
1394         aFont = rStyleSettings.GetFieldFont();
1395         SetPointFont( aFont );
1396     }
1397 
1398     if( bForeground || bFont )
1399     {
1400         SetTextColor( rStyleSettings.GetFieldTextColor() );
1401         SetTextFillColor();
1402     }
1403 
1404     if( bBackground )
1405         SetBackground( rStyleSettings.GetFieldColor() );
1406 }
1407 
1408 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > DialogWindow::CreateAccessible()
1409 {
1410     return (::com::sun::star::accessibility::XAccessible*) new AccessibleDialogWindow( this );
1411 }
1412