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