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