bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / basicide / baside3.cxx
blob9ebb90ed280bb59a674e97fee94e21a9c0c6472a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "basidesh.hrc"
21 #include "helpid.hrc"
23 #include "accessibledialogwindow.hxx"
24 #include "baside3.hxx"
25 #include "basidesh.hxx"
26 #include "bastype2.hxx"
27 #include "dlged.hxx"
28 #include "dlgeddef.hxx"
29 #include "dlgedmod.hxx"
30 #include "dlgedview.hxx"
31 #include "iderdll.hxx"
32 #include "idetemp.hxx"
33 #include "localizationmgr.hxx"
34 #include "managelang.hxx"
36 #include <basic/basmgr.hxx>
37 #include <com/sun/star/resource/StringResourceWithLocation.hpp>
38 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
39 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
40 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
41 #include <com/sun/star/ui/dialogs/FilePicker.hpp>
42 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <sfx2/request.hxx>
46 #include <svl/aeitem.hxx>
47 #include <svl/visitem.hxx>
48 #include <svl/whiter.hxx>
49 #include <tools/diagnose_ex.h>
50 #include <tools/urlobj.hxx>
51 #include <vcl/layout.hxx>
52 #include <vcl/msgbox.hxx>
53 #include <vcl/settings.hxx>
54 #include <xmlscript/xmldlg_imexp.hxx>
56 namespace basctl
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::ucb;
62 using namespace ::com::sun::star::io;
63 using namespace ::com::sun::star::resource;
64 using namespace ::com::sun::star::ui::dialogs;
66 #ifdef WNT
67 char const FilterMask_All[] = "*.*";
68 #else
69 char const FilterMask_All[] = "*";
70 #endif
72 TYPEINIT1( DialogWindow, BaseWindow );
74 DialogWindow::DialogWindow(DialogWindowLayout* pParent, ScriptDocument const& rDocument,
75 const OUString& aLibName, const OUString& aName,
76 css::uno::Reference<css::container::XNameContainer> const& xDialogModel)
77 : BaseWindow(pParent, rDocument, aLibName, aName)
78 ,rLayout(*pParent)
79 ,pEditor(new DlgEditor(*this, rLayout, rDocument.isDocument()
80 ? rDocument.getDocument()
81 : Reference<frame::XModel>(), xDialogModel))
82 ,pUndoMgr(new SfxUndoManager)
84 InitSettings( true, true, true );
86 pEditor->GetModel().SetNotifyUndoActionHdl(
87 LINK(this, DialogWindow, NotifyUndoActionHdl)
90 SetHelpId( HID_BASICIDE_DIALOGWINDOW );
92 // set readonly mode for readonly libraries
93 Reference< script::XLibraryContainer2 > xDlgLibContainer( GetDocument().getLibraryContainer( E_DIALOGS ), UNO_QUERY );
94 if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) )
95 SetReadOnly(true);
97 if ( rDocument.isDocument() && rDocument.isReadOnly() )
98 SetReadOnly(true);
101 void DialogWindow::dispose()
103 pEditor.reset();
104 BaseWindow::dispose();
107 void DialogWindow::LoseFocus()
109 if ( IsModified() )
110 StoreData();
112 Window::LoseFocus();
115 void DialogWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
117 pEditor->Paint(rRenderContext, rRect);
120 void DialogWindow::Resize()
122 if (GetHScrollBar() && GetVScrollBar())
124 pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
128 void DialogWindow::MouseButtonDown( const MouseEvent& rMEvt )
130 pEditor->MouseButtonDown( rMEvt );
132 if (SfxBindings* pBindings = GetBindingsPtr())
133 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
136 void DialogWindow::MouseButtonUp( const MouseEvent& rMEvt )
138 pEditor->MouseButtonUp( rMEvt );
139 if( (pEditor->GetMode() == DlgEditor::INSERT) && !pEditor->IsCreateOK() )
141 pEditor->SetMode( DlgEditor::SELECT );
142 if (SfxBindings* pBindings = GetBindingsPtr())
143 pBindings->Invalidate( SID_CHOOSE_CONTROLS );
145 if (SfxBindings* pBindings = GetBindingsPtr())
147 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
148 pBindings->Invalidate( SID_DOC_MODIFIED );
149 pBindings->Invalidate( SID_SAVEDOC );
150 pBindings->Invalidate( SID_COPY );
151 pBindings->Invalidate( SID_CUT );
155 void DialogWindow::MouseMove( const MouseEvent& rMEvt )
157 pEditor->MouseMove( rMEvt );
160 void DialogWindow::KeyInput( const KeyEvent& rKEvt )
162 SfxBindings* pBindings = GetBindingsPtr();
164 if( rKEvt.GetKeyCode() == KEY_BACKSPACE )
166 if (SfxDispatcher* pDispatcher = GetDispatcher())
167 pDispatcher->Execute( SID_BACKSPACE );
169 else
171 if( pBindings && rKEvt.GetKeyCode() == KEY_TAB )
172 pBindings->Invalidate( SID_SHOW_PROPERTYBROWSER );
174 if( !pEditor->KeyInput( rKEvt ) )
176 if( !SfxViewShell::Current()->KeyInput( rKEvt ) )
177 Window::KeyInput( rKEvt );
181 // may be KEY_TAB, KEY_BACKSPACE, KEY_ESCAPE
182 if( pBindings )
184 pBindings->Invalidate( SID_COPY );
185 pBindings->Invalidate( SID_CUT );
189 void DialogWindow::Command( const CommandEvent& rCEvt )
191 if ( ( rCEvt.GetCommand() == CommandEventId::Wheel ) ||
192 ( rCEvt.GetCommand() == CommandEventId::StartAutoScroll ) ||
193 ( rCEvt.GetCommand() == CommandEventId::AutoScroll ) )
195 HandleScrollCommand( rCEvt, GetHScrollBar(), GetVScrollBar() );
197 else if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
199 if (SfxDispatcher* pDispatcher = GetDispatcher())
201 SdrView& rView = GetView();
202 if( !rCEvt.IsMouseEvent() && rView.AreObjectsMarked() )
204 Rectangle aMarkedRect( rView.GetMarkedRect() );
205 Point MarkedCenter( aMarkedRect.Center() );
206 Point PosPixel( LogicToPixel( MarkedCenter ) );
207 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED), this, &PosPixel );
209 else
211 pDispatcher->ExecutePopup( IDEResId(RID_POPUP_DLGED) );
216 else
217 BaseWindow::Command( rCEvt );
223 IMPL_STATIC_LINK(
224 DialogWindow, NotifyUndoActionHdl, SfxUndoAction *, pUndoAction )
226 // #i120515# pUndoAction needs to be deleted, this hand over is an ownership
227 // change. As long as it does not get added to the undo manager, it needs at
228 // least to be deleted.
229 delete pUndoAction;
231 return 0;
234 void DialogWindow::DoInit()
236 GetHScrollBar()->Show();
237 GetVScrollBar()->Show();
238 pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() );
241 void DialogWindow::DoScroll( ScrollBar* pCurScrollBar )
243 pEditor->DoScroll( pCurScrollBar );
246 void DialogWindow::GetState( SfxItemSet& rSet )
248 SfxWhichIter aIter(rSet);
249 bool bIsCalc = false;
250 if ( GetDocument().isDocument() )
252 Reference< frame::XModel > xModel= GetDocument().getDocument();
253 if ( xModel.is() )
255 Reference< lang::XServiceInfo > xServiceInfo ( xModel, UNO_QUERY );
256 if ( xServiceInfo.is() && xServiceInfo->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
257 bIsCalc = true;
261 for ( sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
263 switch ( nWh )
265 case SID_PASTE:
267 if ( !IsPasteAllowed() )
268 rSet.DisableItem( nWh );
270 if ( IsReadOnly() )
271 rSet.DisableItem( nWh );
273 break;
274 case SID_COPY:
276 // any object selected?
277 if ( !pEditor->GetView().AreObjectsMarked() )
278 rSet.DisableItem( nWh );
280 break;
281 case SID_CUT:
282 case SID_DELETE:
283 case SID_BACKSPACE:
285 // any object selected?
286 if ( !pEditor->GetView().AreObjectsMarked() )
287 rSet.DisableItem( nWh );
289 if ( IsReadOnly() )
290 rSet.DisableItem( nWh );
292 break;
293 case SID_REDO:
295 if ( !pUndoMgr->GetUndoActionCount() )
296 rSet.DisableItem( nWh );
298 break;
300 case SID_DIALOG_TESTMODE:
302 // is the IDE still active?
303 bool const bBool = GetShell()->GetFrame() &&
304 pEditor->GetMode() == DlgEditor::TEST;
305 rSet.Put(SfxBoolItem(SID_DIALOG_TESTMODE, bBool));
307 break;
309 case SID_CHOOSE_CONTROLS:
311 if ( IsReadOnly() )
313 rSet.DisableItem( nWh );
315 else
317 SfxAllEnumItem aItem( SID_CHOOSE_CONTROLS );
318 if ( GetEditor().GetMode() == DlgEditor::SELECT )
319 aItem.SetValue( SVX_SNAP_SELECT );
320 else
322 sal_uInt16 nObj;
323 switch( pEditor->GetInsertObj() )
325 case OBJ_DLG_PUSHBUTTON: nObj = SVX_SNAP_PUSHBUTTON; break;
326 case OBJ_DLG_RADIOBUTTON: nObj = SVX_SNAP_RADIOBUTTON; break;
327 case OBJ_DLG_CHECKBOX: nObj = SVX_SNAP_CHECKBOX; break;
328 case OBJ_DLG_LISTBOX: nObj = SVX_SNAP_LISTBOX; break;
329 case OBJ_DLG_COMBOBOX: nObj = SVX_SNAP_COMBOBOX; break;
330 case OBJ_DLG_GROUPBOX: nObj = SVX_SNAP_GROUPBOX; break;
331 case OBJ_DLG_EDIT: nObj = SVX_SNAP_EDIT; break;
332 case OBJ_DLG_FIXEDTEXT: nObj = SVX_SNAP_FIXEDTEXT; break;
333 case OBJ_DLG_IMAGECONTROL: nObj = SVX_SNAP_IMAGECONTROL; break;
334 case OBJ_DLG_PROGRESSBAR: nObj = SVX_SNAP_PROGRESSBAR; break;
335 case OBJ_DLG_HSCROLLBAR: nObj = SVX_SNAP_HSCROLLBAR; break;
336 case OBJ_DLG_VSCROLLBAR: nObj = SVX_SNAP_VSCROLLBAR; break;
337 case OBJ_DLG_HFIXEDLINE: nObj = SVX_SNAP_HFIXEDLINE; break;
338 case OBJ_DLG_VFIXEDLINE: nObj = SVX_SNAP_VFIXEDLINE; break;
339 case OBJ_DLG_DATEFIELD: nObj = SVX_SNAP_DATEFIELD; break;
340 case OBJ_DLG_TIMEFIELD: nObj = SVX_SNAP_TIMEFIELD; break;
341 case OBJ_DLG_NUMERICFIELD: nObj = SVX_SNAP_NUMERICFIELD; break;
342 case OBJ_DLG_CURRENCYFIELD: nObj = SVX_SNAP_CURRENCYFIELD; break;
343 case OBJ_DLG_FORMATTEDFIELD: nObj = SVX_SNAP_FORMATTEDFIELD; break;
344 case OBJ_DLG_PATTERNFIELD: nObj = SVX_SNAP_PATTERNFIELD; break;
345 case OBJ_DLG_FILECONTROL: nObj = SVX_SNAP_FILECONTROL; break;
346 case OBJ_DLG_SPINBUTTON: nObj = SVX_SNAP_SPINBUTTON; break;
347 case OBJ_DLG_TREECONTROL: nObj = SVX_SNAP_TREECONTROL; break;
348 default: nObj = 0;
350 #ifdef DBG_UTIL
351 if( !nObj )
353 DBG_WARNING( "SID_CHOOSE_CONTROLS: Unbekannt!" );
355 #endif
356 aItem.SetValue( nObj );
359 rSet.Put( aItem );
362 break;
364 case SID_SHOW_PROPERTYBROWSER:
366 Shell* pShell = GetShell();
367 SfxViewFrame* pViewFrame = pShell ? pShell->GetViewFrame() : NULL;
368 if ( pViewFrame && !pViewFrame->HasChildWindow( SID_SHOW_PROPERTYBROWSER ) && !pEditor->GetView().AreObjectsMarked() )
369 rSet.DisableItem( nWh );
371 if ( IsReadOnly() )
372 rSet.DisableItem( nWh );
374 break;
375 case SID_INSERT_FORM_RADIO:
376 case SID_INSERT_FORM_CHECK:
377 case SID_INSERT_FORM_LIST:
378 case SID_INSERT_FORM_COMBO:
379 case SID_INSERT_FORM_VSCROLL:
380 case SID_INSERT_FORM_HSCROLL:
381 case SID_INSERT_FORM_SPIN:
383 if ( !bIsCalc || IsReadOnly() )
384 rSet.DisableItem( nWh );
386 break;
387 case SID_SHOWLINES:
389 // if this is not a module window hide the
390 // setting, doesn't make sense for example if the
391 // dialog editor is open
392 rSet.DisableItem(nWh);
393 rSet.Put(SfxVisibilityItem(nWh, false));
394 break;
396 case SID_SELECTALL:
398 rSet.DisableItem( nWh );
400 break;
405 void DialogWindow::ExecuteCommand( SfxRequest& rReq )
407 switch ( rReq.GetSlot() )
409 case SID_CUT:
410 if ( !IsReadOnly() )
412 GetEditor().Cut();
413 if (SfxBindings* pBindings = GetBindingsPtr())
414 pBindings->Invalidate( SID_DOC_MODIFIED );
416 break;
417 case SID_DELETE:
418 if ( !IsReadOnly() )
420 GetEditor().Delete();
421 if (SfxBindings* pBindings = GetBindingsPtr())
422 pBindings->Invalidate( SID_DOC_MODIFIED );
424 break;
425 case SID_COPY:
426 GetEditor().Copy();
427 break;
428 case SID_PASTE:
429 if ( !IsReadOnly() )
431 GetEditor().Paste();
432 if (SfxBindings* pBindings = GetBindingsPtr())
433 pBindings->Invalidate( SID_DOC_MODIFIED );
435 break;
436 case SID_INSERT_FORM_RADIO:
437 GetEditor().SetMode( DlgEditor::INSERT );
438 GetEditor().SetInsertObj( OBJ_DLG_FORMRADIO );
439 break;
440 case SID_INSERT_FORM_CHECK:
441 GetEditor().SetMode( DlgEditor::INSERT );
442 GetEditor().SetInsertObj( OBJ_DLG_FORMCHECK );
443 break;
444 case SID_INSERT_FORM_LIST:
445 GetEditor().SetMode( DlgEditor::INSERT );
446 GetEditor().SetInsertObj( OBJ_DLG_FORMLIST );
447 break;
448 case SID_INSERT_FORM_COMBO:
449 GetEditor().SetMode( DlgEditor::INSERT );
450 GetEditor().SetInsertObj( OBJ_DLG_FORMCOMBO );
451 break;
452 case SID_INSERT_FORM_SPIN:
453 GetEditor().SetMode( DlgEditor::INSERT );
454 GetEditor().SetInsertObj( OBJ_DLG_FORMSPIN );
455 break;
456 case SID_INSERT_FORM_VSCROLL:
457 GetEditor().SetMode( DlgEditor::INSERT );
458 GetEditor().SetInsertObj( OBJ_DLG_FORMVSCROLL );
459 break;
460 case SID_INSERT_FORM_HSCROLL:
461 GetEditor().SetMode( DlgEditor::INSERT );
462 GetEditor().SetInsertObj( OBJ_DLG_FORMHSCROLL );
463 break;
464 case SID_CHOOSE_CONTROLS:
466 const SfxItemSet* pArgs = rReq.GetArgs();
467 DBG_ASSERT( pArgs, "Nix Args" );
469 const SfxAllEnumItem& rItem = static_cast<const SfxAllEnumItem&>(pArgs->Get( SID_CHOOSE_CONTROLS ));
470 switch( rItem.GetValue() )
472 case SVX_SNAP_PUSHBUTTON:
474 GetEditor().SetMode( DlgEditor::INSERT );
475 GetEditor().SetInsertObj( OBJ_DLG_PUSHBUTTON );
477 break;
478 case SVX_SNAP_RADIOBUTTON:
480 GetEditor().SetMode( DlgEditor::INSERT );
481 GetEditor().SetInsertObj( OBJ_DLG_RADIOBUTTON );
483 break;
484 case SVX_SNAP_CHECKBOX:
486 GetEditor().SetMode( DlgEditor::INSERT );
487 GetEditor().SetInsertObj( OBJ_DLG_CHECKBOX);
489 break;
490 case SVX_SNAP_LISTBOX:
492 GetEditor().SetMode( DlgEditor::INSERT );
493 GetEditor().SetInsertObj( OBJ_DLG_LISTBOX );
495 break;
496 case SVX_SNAP_COMBOBOX:
498 GetEditor().SetMode( DlgEditor::INSERT );
499 GetEditor().SetInsertObj( OBJ_DLG_COMBOBOX );
501 break;
502 case SVX_SNAP_GROUPBOX:
504 GetEditor().SetMode( DlgEditor::INSERT );
505 GetEditor().SetInsertObj( OBJ_DLG_GROUPBOX );
507 break;
508 case SVX_SNAP_EDIT:
510 GetEditor().SetMode( DlgEditor::INSERT );
511 GetEditor().SetInsertObj( OBJ_DLG_EDIT );
513 break;
514 case SVX_SNAP_FIXEDTEXT:
516 GetEditor().SetMode( DlgEditor::INSERT );
517 GetEditor().SetInsertObj( OBJ_DLG_FIXEDTEXT );
519 break;
520 case SVX_SNAP_IMAGECONTROL:
522 GetEditor().SetMode( DlgEditor::INSERT );
523 GetEditor().SetInsertObj( OBJ_DLG_IMAGECONTROL );
525 break;
526 case SVX_SNAP_PROGRESSBAR:
528 GetEditor().SetMode( DlgEditor::INSERT );
529 GetEditor().SetInsertObj( OBJ_DLG_PROGRESSBAR );
531 break;
532 case SVX_SNAP_HSCROLLBAR:
534 GetEditor().SetMode( DlgEditor::INSERT );
535 GetEditor().SetInsertObj( OBJ_DLG_HSCROLLBAR );
537 break;
538 case SVX_SNAP_VSCROLLBAR:
540 GetEditor().SetMode( DlgEditor::INSERT );
541 GetEditor().SetInsertObj( OBJ_DLG_VSCROLLBAR );
543 break;
544 case SVX_SNAP_HFIXEDLINE:
546 GetEditor().SetMode( DlgEditor::INSERT );
547 GetEditor().SetInsertObj( OBJ_DLG_HFIXEDLINE );
549 break;
550 case SVX_SNAP_VFIXEDLINE:
552 GetEditor().SetMode( DlgEditor::INSERT );
553 GetEditor().SetInsertObj( OBJ_DLG_VFIXEDLINE );
555 break;
556 case SVX_SNAP_DATEFIELD:
558 GetEditor().SetMode( DlgEditor::INSERT );
559 GetEditor().SetInsertObj( OBJ_DLG_DATEFIELD );
561 break;
562 case SVX_SNAP_TIMEFIELD:
564 GetEditor().SetMode( DlgEditor::INSERT );
565 GetEditor().SetInsertObj( OBJ_DLG_TIMEFIELD );
567 break;
568 case SVX_SNAP_NUMERICFIELD:
570 GetEditor().SetMode( DlgEditor::INSERT );
571 GetEditor().SetInsertObj( OBJ_DLG_NUMERICFIELD );
573 break;
574 case SVX_SNAP_CURRENCYFIELD:
576 GetEditor().SetMode( DlgEditor::INSERT );
577 GetEditor().SetInsertObj( OBJ_DLG_CURRENCYFIELD );
579 break;
580 case SVX_SNAP_FORMATTEDFIELD:
582 GetEditor().SetMode( DlgEditor::INSERT );
583 GetEditor().SetInsertObj( OBJ_DLG_FORMATTEDFIELD );
585 break;
586 case SVX_SNAP_PATTERNFIELD:
588 GetEditor().SetMode( DlgEditor::INSERT );
589 GetEditor().SetInsertObj( OBJ_DLG_PATTERNFIELD );
591 break;
592 case SVX_SNAP_FILECONTROL:
594 GetEditor().SetMode( DlgEditor::INSERT );
595 GetEditor().SetInsertObj( OBJ_DLG_FILECONTROL );
597 break;
598 case SVX_SNAP_SPINBUTTON:
600 GetEditor().SetMode( DlgEditor::INSERT );
601 GetEditor().SetInsertObj( OBJ_DLG_SPINBUTTON );
603 break;
604 case SVX_SNAP_TREECONTROL:
606 GetEditor().SetMode( DlgEditor::INSERT );
607 GetEditor().SetInsertObj( OBJ_DLG_TREECONTROL );
609 break;
611 case SVX_SNAP_SELECT:
613 GetEditor().SetMode( DlgEditor::SELECT );
615 break;
618 if ( rReq.GetModifier() & KEY_MOD1 )
620 if ( GetEditor().GetMode() == DlgEditor::INSERT )
621 GetEditor().CreateDefaultObject();
624 if (SfxBindings* pBindings = GetBindingsPtr())
625 pBindings->Invalidate( SID_DOC_MODIFIED );
627 break;
629 case SID_DIALOG_TESTMODE:
631 DlgEditor::Mode eOldMode = GetEditor().GetMode();
632 GetEditor().SetMode( DlgEditor::TEST );
633 GetEditor().SetMode( eOldMode );
634 rReq.Done();
635 if (SfxBindings* pBindings = GetBindingsPtr())
636 pBindings->Invalidate( SID_DIALOG_TESTMODE );
637 return;
639 case SID_EXPORT_DIALOG:
640 SaveDialog();
641 break;
643 case SID_IMPORT_DIALOG:
644 ImportDialog();
645 break;
647 case SID_BASICIDE_DELETECURRENT:
648 if (QueryDelDialog(m_aName, this))
650 if (RemoveDialog(m_aDocument, m_aLibName, m_aName))
652 MarkDocumentModified(m_aDocument);
653 GetShell()->RemoveWindow(this, true);
656 break;
659 rReq.Done();
662 Reference< container::XNameContainer > DialogWindow::GetDialog() const
664 return pEditor->GetDialog();
667 bool DialogWindow::RenameDialog( const OUString& rNewName )
669 if ( !basctl::RenameDialog( this, GetDocument(), GetLibName(), GetName(), rNewName ) )
670 return false;
672 if (SfxBindings* pBindings = GetBindingsPtr())
673 pBindings->Invalidate( SID_DOC_MODIFIED );
675 return true;
678 void DialogWindow::DisableBrowser()
680 rLayout.DisablePropertyBrowser();
683 void DialogWindow::UpdateBrowser()
685 rLayout.UpdatePropertyBrowser();
688 bool DialogWindow::SaveDialog()
690 bool bDone = false;
692 Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
693 Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD);
695 Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
696 xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false);
697 Any aValue;
698 aValue <<= true;
699 xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
701 if ( !aCurPath.isEmpty() )
702 xFP->setDisplayDirectory ( aCurPath );
704 xFP->setDefaultName( OUString( GetName() ) );
706 OUString aDialogStr(IDE_RESSTR(RID_STR_STDDIALOGNAME));
707 xFP->appendFilter( aDialogStr, OUString( "*.xdl" ) );
708 xFP->appendFilter( IDE_RESSTR(RID_STR_FILTER_ALLFILES), OUString( FilterMask_All ) );
709 xFP->setCurrentFilter( aDialogStr );
711 if( xFP->execute() == RET_OK )
713 Sequence< OUString > aPaths = xFP->getFiles();
714 aCurPath = aPaths[0];
716 // export dialog model to xml
717 Reference< container::XNameContainer > xDialogModel = GetDialog();
718 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().isDocument() ? GetDocument().getDocument() : Reference< frame::XModel >() );
719 Reference< XInputStream > xInput( xISP->createInputStream() );
721 Reference< XSimpleFileAccess3 > xSFI( SimpleFileAccess::create(xContext) );
723 Reference< XOutputStream > xOutput;
726 if( xSFI->exists( aCurPath ) )
727 xSFI->kill( aCurPath );
728 xOutput = xSFI->openFileWrite( aCurPath );
730 catch(const Exception& )
733 if( xOutput.is() )
735 Sequence< sal_Int8 > bytes;
736 sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() );
737 for (;;)
739 if( nRead )
740 xOutput->writeBytes( bytes );
742 nRead = xInput->readBytes( bytes, 1024 );
743 if (! nRead)
744 break;
746 bDone = true;
748 // With resource?
749 Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
750 Reference< resource::XStringResourceResolver > xStringResourceResolver;
751 if( xDialogModelPropSet.is() )
755 Any aResourceResolver = xDialogModelPropSet->getPropertyValue( "ResourceResolver" );
756 aResourceResolver >>= xStringResourceResolver;
758 catch(const beans::UnknownPropertyException& )
762 bool bResource = false;
763 if( xStringResourceResolver.is() )
765 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
766 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
767 if( nLocaleCount > 0 )
768 bResource = true;
771 if( bResource )
773 INetURLObject aURLObj( aCurPath );
774 aURLObj.removeExtension();
775 OUString aDialogName( aURLObj.getName() );
776 aURLObj.removeSegment();
777 OUString aURL( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) );
778 bool bReadOnly = false;
779 OUString aComment( "# " );
780 aComment += aDialogName;
781 aComment += " strings" ;
782 Reference< task::XInteractionHandler > xDummyHandler;
784 // Remove old properties files in case of overwriting Dialog files
785 if( xSFI->isFolder( aURL ) )
787 Sequence< OUString > aContentSeq = xSFI->getFolderContents( aURL, false );
789 OUString aDialogName_( aDialogName );
790 aDialogName_ += "_" ;
791 sal_Int32 nCount = aContentSeq.getLength();
792 const OUString* pFiles = aContentSeq.getConstArray();
793 for( int i = 0 ; i < nCount ; i++ )
795 OUString aCompleteName = pFiles[i];
796 OUString aPureName;
797 OUString aExtension;
798 sal_Int32 iDot = aCompleteName.lastIndexOf( '.' );
799 sal_Int32 iSlash = aCompleteName.lastIndexOf( '/' );
800 if( iDot != -1 )
802 sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0;
803 aPureName = aCompleteName.copy( iCopyFrom, iDot-iCopyFrom );
804 aExtension = aCompleteName.copy( iDot + 1 );
807 if( aExtension == "properties" || aExtension == "default" )
809 if( aPureName.startsWith( aDialogName_ ) )
813 xSFI->kill( aCompleteName );
815 catch(const uno::Exception& )
822 Reference< XStringResourceWithLocation > xStringResourceWithLocation =
823 StringResourceWithLocation::create( xContext, aURL, bReadOnly,
824 xStringResourceResolver->getDefaultLocale(), aDialogName, aComment, xDummyHandler );
826 // Add locales
827 Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales();
828 const lang::Locale* pLocales = aLocaleSeq.getConstArray();
829 sal_Int32 nLocaleCount = aLocaleSeq.getLength();
830 for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ )
832 const lang::Locale& rLocale = pLocales[ iLocale ];
833 xStringResourceWithLocation->newLocale( rLocale );
836 LocalizationMgr::copyResourceForDialog( xDialogModel,
837 xStringResourceResolver, xStringResourceWithLocation );
839 xStringResourceWithLocation->store();
842 else
843 ScopedVclPtrInstance<MessageDialog>::Create(this, IDE_RESSTR(RID_STR_COULDNTWRITE))->Execute();
846 return bDone;
849 std::vector< lang::Locale > implGetLanguagesOnlyContainedInFirstSeq
850 ( const Sequence< lang::Locale >& aFirstSeq, const Sequence< lang::Locale >& aSecondSeq )
852 std::vector< lang::Locale > avRet;
854 const lang::Locale* pFirst = aFirstSeq.getConstArray();
855 const lang::Locale* pSecond = aSecondSeq.getConstArray();
856 sal_Int32 nFirstCount = aFirstSeq.getLength();
857 sal_Int32 nSecondCount = aSecondSeq.getLength();
859 for( sal_Int32 iFirst = 0 ; iFirst < nFirstCount ; iFirst++ )
861 const lang::Locale& rFirstLocale = pFirst[ iFirst ];
863 bool bAlsoContainedInSecondSeq = false;
864 for( sal_Int32 iSecond = 0 ; iSecond < nSecondCount ; iSecond++ )
866 const lang::Locale& rSecondLocale = pSecond[ iSecond ];
868 bool bMatch = localesAreEqual( rFirstLocale, rSecondLocale );
869 if( bMatch )
871 bAlsoContainedInSecondSeq = true;
872 break;
876 if( !bAlsoContainedInSecondSeq )
877 avRet.push_back( rFirstLocale );
880 return avRet;
884 class NameClashQueryBox : public MessBox
886 public:
887 NameClashQueryBox( vcl::Window* pParent,
888 const OUString& rTitle, const OUString& rMessage );
891 NameClashQueryBox::NameClashQueryBox( vcl::Window* pParent,
892 const OUString& rTitle, const OUString& rMessage )
893 : MessBox( pParent, 0, rTitle, rMessage )
895 if ( !rTitle.isEmpty() )
896 SetText( rTitle );
898 maMessText = rMessage;
900 AddButton( IDE_RESSTR(RID_STR_DLGIMP_CLASH_RENAME), RET_YES,
901 ButtonDialogFlags::Default | ButtonDialogFlags::OK | ButtonDialogFlags::Focus );
902 AddButton( IDE_RESSTR(RID_STR_DLGIMP_CLASH_REPLACE), RET_NO );
903 AddButton( StandardButtonType::Cancel, RET_CANCEL, ButtonDialogFlags::Cancel );
905 SetImage( QueryBox::GetStandardImage() );
909 class LanguageMismatchQueryBox : public MessBox
911 public:
912 LanguageMismatchQueryBox( vcl::Window* pParent,
913 const OUString& rTitle, const OUString& rMessage );
916 LanguageMismatchQueryBox::LanguageMismatchQueryBox( vcl::Window* pParent,
917 const OUString& rTitle, const OUString& rMessage )
918 : MessBox( pParent, 0, rTitle, rMessage )
920 if ( !rTitle.isEmpty() )
921 SetText( rTitle );
923 maMessText = rMessage;
924 AddButton( IDE_RESSTR(RID_STR_DLGIMP_MISMATCH_ADD), RET_YES,
925 ButtonDialogFlags::Default | ButtonDialogFlags::OK | ButtonDialogFlags::Focus );
926 AddButton( IDE_RESSTR(RID_STR_DLGIMP_MISMATCH_OMIT), RET_NO );
927 AddButton( StandardButtonType::Cancel, RET_CANCEL, ButtonDialogFlags::Cancel );
928 AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 4 );
930 SetImage( QueryBox::GetStandardImage() );
934 bool implImportDialog( vcl::Window* pWin, const OUString& rCurPath, const ScriptDocument& rDocument, const OUString& aLibName )
936 bool bDone = false;
938 Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
939 Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE);
941 Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
942 xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false);
943 Any aValue;
944 aValue <<= true;
945 xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
947 OUString aCurPath( rCurPath );
948 if ( !aCurPath.isEmpty() )
949 xFP->setDisplayDirectory ( aCurPath );
951 OUString aDialogStr(IDE_RESSTR(RID_STR_STDDIALOGNAME));
952 xFP->appendFilter( aDialogStr, OUString( "*.xdl" ) );
953 xFP->appendFilter( IDE_RESSTR(RID_STR_FILTER_ALLFILES), OUString( FilterMask_All ) );
954 xFP->setCurrentFilter( aDialogStr );
956 if( xFP->execute() == RET_OK )
958 Sequence< OUString > aPaths = xFP->getFiles();
959 aCurPath = aPaths[0];
961 OUString aBasePath;
962 OUString aOUCurPath( aCurPath );
963 sal_Int32 iSlash = aOUCurPath.lastIndexOf( '/' );
964 if( iSlash != -1 )
965 aBasePath = aOUCurPath.copy( 0, iSlash + 1 );
969 // create dialog model
970 Reference< container::XNameContainer > xDialogModel(
971 xContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", xContext),
972 UNO_QUERY_THROW );
974 Reference< XSimpleFileAccess3 > xSFI( SimpleFileAccess::create(xContext) );
976 Reference< XInputStream > xInput;
977 if( xSFI->exists( aCurPath ) )
978 xInput = xSFI->openFileRead( aCurPath );
980 ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
982 OUString aXmlDlgName;
983 Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY );
984 if( xDialogModelPropSet.is() )
988 Any aXmlDialogNameAny = xDialogModelPropSet->getPropertyValue( DLGED_PROP_NAME );
989 OUString aOUXmlDialogName;
990 aXmlDialogNameAny >>= aOUXmlDialogName;
991 aXmlDlgName = aOUXmlDialogName;
993 catch(const beans::UnknownPropertyException& )
996 bool bValidName = !aXmlDlgName.isEmpty();
997 OSL_ASSERT( bValidName );
998 if( !bValidName )
999 return bDone;
1001 bool bDialogAlreadyExists = rDocument.hasDialog( aLibName, aXmlDlgName );
1003 OUString aNewDlgName = aXmlDlgName;
1004 enum NameClashMode
1006 NO_CLASH,
1007 CLASH_OVERWRITE_DIALOG,
1008 CLASH_RENAME_DIALOG,
1010 NameClashMode eNameClashMode = NO_CLASH;
1011 if( bDialogAlreadyExists )
1013 OUString aQueryBoxTitle(IDE_RESSTR(RID_STR_DLGIMP_CLASH_TITLE));
1014 OUString aQueryBoxText(IDE_RESSTR(RID_STR_DLGIMP_CLASH_TEXT));
1015 aQueryBoxText = aQueryBoxText.replaceAll("$(ARG1)", aXmlDlgName);
1017 ScopedVclPtrInstance< NameClashQueryBox > aQueryBox( pWin, aQueryBoxTitle, aQueryBoxText );
1018 sal_uInt16 nRet = aQueryBox->Execute();
1019 if( RET_YES == nRet )
1021 // RET_YES == Rename, see NameClashQueryBox::NameClashQueryBox
1022 eNameClashMode = CLASH_RENAME_DIALOG;
1024 aNewDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
1026 else if( RET_NO == nRet )
1028 // RET_NO == Replace, see NameClashQueryBox::NameClashQueryBox
1029 eNameClashMode = CLASH_OVERWRITE_DIALOG;
1031 else if( RET_CANCEL == nRet )
1033 return bDone;
1037 Shell* pShell = GetShell();
1038 if (!pShell)
1040 OSL_ASSERT(pShell);
1041 return bDone;
1044 // Resource?
1045 ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
1046 Reference< task::XInteractionHandler > xDummyHandler;
1047 bool bReadOnly = true;
1048 Reference< XStringResourceWithLocation > xImportStringResource =
1049 StringResourceWithLocation::create( xContext, aBasePath, bReadOnly,
1050 aLocale, aXmlDlgName, OUString(), xDummyHandler );
1052 Sequence< lang::Locale > aImportLocaleSeq = xImportStringResource->getLocales();
1053 sal_Int32 nImportLocaleCount = aImportLocaleSeq.getLength();
1055 Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
1056 Reference< resource::XStringResourceManager > xLibStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
1057 sal_Int32 nLibLocaleCount = 0;
1058 Sequence< lang::Locale > aLibLocaleSeq;
1059 if( xLibStringResourceManager.is() )
1061 aLibLocaleSeq = xLibStringResourceManager->getLocales();
1062 nLibLocaleCount = aLibLocaleSeq.getLength();
1065 // Check language matches
1066 std::vector< lang::Locale > aOnlyInImportLanguages =
1067 implGetLanguagesOnlyContainedInFirstSeq( aImportLocaleSeq, aLibLocaleSeq );
1068 int nOnlyInImportLanguageCount = aOnlyInImportLanguages.size();
1070 // For now: Keep languages from lib
1071 bool bLibLocalized = (nLibLocaleCount > 0);
1072 bool bImportLocalized = (nImportLocaleCount > 0);
1074 bool bAddDialogLanguagesToLib = false;
1075 if( nOnlyInImportLanguageCount > 0 )
1077 OUString aQueryBoxTitle(IDE_RESSTR(RID_STR_DLGIMP_MISMATCH_TITLE));
1078 OUString aQueryBoxText(IDE_RESSTR(RID_STR_DLGIMP_MISMATCH_TEXT));
1079 ScopedVclPtrInstance< LanguageMismatchQueryBox > aQueryBox( pWin, aQueryBoxTitle, aQueryBoxText );
1080 sal_uInt16 nRet = aQueryBox->Execute();
1081 if( RET_YES == nRet )
1083 // RET_YES == Add, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
1084 bAddDialogLanguagesToLib = true;
1086 // RET_NO == Omit, see LanguageMismatchQueryBox::LanguageMismatchQueryBox
1087 // -> nothing to do here
1088 //else if( RET_NO == nRet )
1091 else if( RET_CANCEL == nRet )
1093 return bDone;
1097 if( bImportLocalized )
1099 bool bCopyResourcesForDialog = true;
1100 if( bAddDialogLanguagesToLib )
1102 boost::shared_ptr<LocalizationMgr> pCurMgr = pShell->GetCurLocalizationMgr();
1104 lang::Locale aFirstLocale;
1105 aFirstLocale = aOnlyInImportLanguages[0];
1106 if( nOnlyInImportLanguageCount > 1 )
1108 // Check if import default belongs to only import languages and use it then
1109 lang::Locale aImportDefaultLocale = xImportStringResource->getDefaultLocale();
1110 lang::Locale aTmpLocale;
1111 for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
1113 aTmpLocale = aOnlyInImportLanguages[i];
1114 if( localesAreEqual( aImportDefaultLocale, aTmpLocale ) )
1116 aFirstLocale = aImportDefaultLocale;
1117 break;
1122 Sequence< lang::Locale > aFirstLocaleSeq( 1 );
1123 aFirstLocaleSeq[0] = aFirstLocale;
1124 pCurMgr->handleAddLocales( aFirstLocaleSeq );
1126 if( nOnlyInImportLanguageCount > 1 )
1128 Sequence< lang::Locale > aRemainingLocaleSeq( nOnlyInImportLanguageCount - 1 );
1129 lang::Locale aTmpLocale;
1130 int iSeq = 0;
1131 for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i )
1133 aTmpLocale = aOnlyInImportLanguages[i];
1134 if( !localesAreEqual( aFirstLocale, aTmpLocale ) )
1135 aRemainingLocaleSeq[iSeq++] = aTmpLocale;
1137 pCurMgr->handleAddLocales( aRemainingLocaleSeq );
1140 else if( !bLibLocalized )
1142 Reference< resource::XStringResourceManager > xImportStringResourceManager( xImportStringResource, UNO_QUERY );
1143 LocalizationMgr::resetResourceForDialog( xDialogModel, xImportStringResourceManager );
1144 bCopyResourcesForDialog = false;
1147 if( bCopyResourcesForDialog )
1149 Reference< resource::XStringResourceResolver > xImportStringResourceResolver( xImportStringResource, UNO_QUERY );
1150 LocalizationMgr::copyResourceForDroppedDialog( xDialogModel, aXmlDlgName,
1151 xLibStringResourceManager, xImportStringResourceResolver );
1154 else if( bLibLocalized )
1156 LocalizationMgr::setResourceIDsForDialog( xDialogModel, xLibStringResourceManager );
1160 LocalizationMgr::setStringResourceAtDialog( rDocument, aLibName, aNewDlgName, xDialogModel );
1162 if( eNameClashMode == CLASH_OVERWRITE_DIALOG )
1164 if (basctl::RemoveDialog( rDocument, aLibName, aNewDlgName ) )
1166 BaseWindow* pDlgWin = pShell->FindDlgWin( rDocument, aLibName, aNewDlgName, false, true );
1167 if( pDlgWin != NULL )
1168 pShell->RemoveWindow( pDlgWin, true );
1169 MarkDocumentModified( rDocument );
1171 else
1173 // TODO: Assertion?
1174 return bDone;
1178 if( eNameClashMode == CLASH_RENAME_DIALOG )
1180 bool bRenamed = false;
1181 if( xDialogModelPropSet.is() )
1185 Any aXmlDialogNameAny;
1186 aXmlDialogNameAny <<= OUString( aNewDlgName );
1187 xDialogModelPropSet->setPropertyValue( DLGED_PROP_NAME, aXmlDialogNameAny );
1188 bRenamed = true;
1190 catch(const beans::UnknownPropertyException& )
1195 if( bRenamed )
1197 LocalizationMgr::renameStringResourceIDs( rDocument, aLibName, aNewDlgName, xDialogModel );
1199 else
1201 // TODO: Assertion?
1202 return bDone;
1206 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() );
1207 bool bSuccess = rDocument.insertDialog( aLibName, aNewDlgName, xISP );
1208 if( bSuccess )
1210 VclPtr<DialogWindow> pNewDlgWin = pShell->CreateDlgWin( rDocument, aLibName, aNewDlgName );
1211 pShell->SetCurWindow( pNewDlgWin, true );
1214 bDone = true;
1216 catch(const Exception& )
1220 return bDone;
1224 bool DialogWindow::ImportDialog()
1226 const ScriptDocument& rDocument = GetDocument();
1227 OUString aLibName = GetLibName();
1228 return implImportDialog( this, aCurPath, rDocument, aLibName );
1231 DlgEdModel& DialogWindow::GetModel() const
1233 return pEditor->GetModel();
1236 DlgEdPage& DialogWindow::GetPage() const
1238 return pEditor->GetPage();
1241 DlgEdView& DialogWindow::GetView() const
1243 return pEditor->GetView();
1246 bool DialogWindow::IsModified()
1248 return pEditor->IsModified();
1251 ::svl::IUndoManager* DialogWindow::GetUndoManager()
1253 return pUndoMgr.get();
1256 OUString DialogWindow::GetTitle()
1258 return GetName();
1261 EntryDescriptor DialogWindow::CreateEntryDescriptor()
1263 ScriptDocument aDocument( GetDocument() );
1264 OUString aLibName( GetLibName() );
1265 OUString aLibSubName;
1266 LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
1267 return EntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, GetName(), OBJ_TYPE_DIALOG );
1270 void DialogWindow::SetReadOnly (bool bReadOnly)
1272 pEditor->SetMode(bReadOnly ? DlgEditor::READONLY : DlgEditor::SELECT);
1275 bool DialogWindow::IsReadOnly ()
1277 return pEditor->GetMode() == DlgEditor::READONLY;
1280 bool DialogWindow::IsPasteAllowed()
1282 return pEditor->IsPasteAllowed();
1285 void DialogWindow::StoreData()
1287 if ( IsModified() )
1291 Reference< container::XNameContainer > xLib = GetDocument().getLibrary( E_DIALOGS, GetLibName(), true );
1293 if( xLib.is() )
1295 Reference< container::XNameContainer > xDialogModel = pEditor->GetDialog();
1297 if( xDialogModel.is() )
1299 Reference< XComponentContext > xContext(
1300 comphelper::getProcessComponentContext() );
1301 Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().isDocument() ? GetDocument().getDocument() : Reference< frame::XModel >() );
1302 xLib->replaceByName( OUString( GetName() ), makeAny( xISP ) );
1306 catch (const uno::Exception& )
1308 DBG_UNHANDLED_EXCEPTION();
1310 MarkDocumentModified( GetDocument() );
1311 pEditor->ClearModifyFlag();
1315 void DialogWindow::Activating ()
1317 UpdateBrowser();
1318 Show();
1321 void DialogWindow::Deactivating()
1323 Hide();
1324 if ( IsModified() )
1325 MarkDocumentModified( GetDocument() );
1326 DisableBrowser();
1329 sal_Int32 DialogWindow::countPages( Printer* )
1331 return 1;
1334 void DialogWindow::printPage( sal_Int32 nPage, Printer* pPrinter )
1336 DlgEditor::printPage( nPage, pPrinter, CreateQualifiedName() );
1339 void DialogWindow::DataChanged( const DataChangedEvent& rDCEvt )
1341 if( (rDCEvt.GetType()==DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
1343 InitSettings( true, true, true );
1344 Invalidate();
1346 else
1347 BaseWindow::DataChanged( rDCEvt );
1350 void DialogWindow::InitSettings(bool bFont, bool bForeground, bool bBackground)
1352 // FIXME RenderContext
1353 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1354 if( bFont )
1356 vcl::Font aFont;
1357 aFont = rStyleSettings.GetFieldFont();
1358 SetPointFont(*this, aFont);
1361 if( bForeground || bFont )
1363 SetTextColor( rStyleSettings.GetFieldTextColor() );
1364 SetTextFillColor();
1367 if( bBackground )
1368 SetBackground( rStyleSettings.GetFieldColor() );
1371 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > DialogWindow::CreateAccessible()
1373 return (::com::sun::star::accessibility::XAccessible*) new AccessibleDialogWindow( this );
1376 char const* DialogWindow::GetHid () const
1378 return HID_BASICIDE_DIALOGWINDOW;
1380 ItemType DialogWindow::GetType () const
1382 return TYPE_DIALOG;
1387 // DialogWindowLayout
1391 DialogWindowLayout::DialogWindowLayout (vcl::Window* pParent, ObjectCatalog& rObjectCatalog_) :
1392 Layout(pParent),
1393 pChild(0),
1394 rObjectCatalog(rObjectCatalog_),
1395 pPropertyBrowser(0)
1397 ShowPropertyBrowser();
1400 DialogWindowLayout::~DialogWindowLayout()
1402 disposeOnce();
1405 void DialogWindowLayout::dispose()
1407 if (pPropertyBrowser)
1408 Remove(pPropertyBrowser);
1409 pPropertyBrowser.disposeAndClear();
1410 pChild.clear();
1411 Layout::dispose();
1414 // shows the property browser (and creates if necessary)
1415 void DialogWindowLayout::ShowPropertyBrowser ()
1417 // not exists?
1418 if (!pPropertyBrowser)
1420 // creating
1421 pPropertyBrowser = VclPtr<PropBrw>::Create(*this);
1422 pPropertyBrowser->Show();
1423 // after OnFirstSize():
1424 if (HasSize())
1425 AddPropertyBrowser();
1426 // updating if necessary
1427 UpdatePropertyBrowser();
1429 else
1430 pPropertyBrowser->Show();
1431 // refreshing the button state
1432 if (SfxBindings* pBindings = GetBindingsPtr())
1433 pBindings->Invalidate(SID_SHOW_PROPERTYBROWSER);
1436 // disables the property browser
1437 void DialogWindowLayout::DisablePropertyBrowser ()
1439 if (pPropertyBrowser)
1440 pPropertyBrowser->Update(0);
1443 // updates the property browser
1444 void DialogWindowLayout::UpdatePropertyBrowser ()
1446 if (pPropertyBrowser)
1447 pPropertyBrowser->Update(GetShell());
1450 void DialogWindowLayout::Activating (BaseWindow& rChild)
1452 assert(dynamic_cast<DialogWindow*>(&rChild));
1453 pChild = &static_cast<DialogWindow&>(rChild);
1454 rObjectCatalog.SetLayoutWindow(this);
1455 rObjectCatalog.UpdateEntries();
1456 rObjectCatalog.Show();
1457 if (pPropertyBrowser)
1458 pPropertyBrowser->Show();
1459 Layout::Activating(rChild);
1462 void DialogWindowLayout::Deactivating ()
1464 Layout::Deactivating();
1465 rObjectCatalog.Hide();
1466 if (pPropertyBrowser)
1467 pPropertyBrowser->Hide();
1468 pChild = 0;
1471 void DialogWindowLayout::ExecuteGlobal (SfxRequest& rReq)
1473 switch (rReq.GetSlot())
1475 case SID_SHOW_PROPERTYBROWSER:
1476 // toggling property browser
1477 if (pPropertyBrowser && pPropertyBrowser->IsVisible())
1478 pPropertyBrowser->Hide();
1479 else
1480 ShowPropertyBrowser();
1481 ArrangeWindows();
1482 // refreshing the button state
1483 if (SfxBindings* pBindings = GetBindingsPtr())
1484 pBindings->Invalidate(SID_SHOW_PROPERTYBROWSER);
1485 break;
1489 void DialogWindowLayout::GetState (SfxItemSet& rSet, unsigned nWhich)
1491 switch (nWhich)
1493 case SID_SHOW_PROPERTYBROWSER:
1494 rSet.Put(SfxBoolItem(nWhich, pPropertyBrowser && pPropertyBrowser->IsVisible()));
1495 break;
1497 case SID_BASICIDE_CHOOSEMACRO:
1498 rSet.Put(SfxVisibilityItem(nWhich, false));
1499 break;
1503 void DialogWindowLayout::OnFirstSize (long const nWidth, long const nHeight)
1505 AddToLeft(&rObjectCatalog, Size(nWidth * 0.25, nHeight * 0.35));
1506 if (pPropertyBrowser)
1507 AddPropertyBrowser();
1510 void DialogWindowLayout::AddPropertyBrowser () {
1511 Size const aSize = GetOutputSizePixel();
1512 AddToLeft(pPropertyBrowser, Size(aSize.Width() * 0.25, aSize.Height() * 0.65));
1516 } // namespace basctl
1518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */