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