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