update dev300-m58
[ooovba.git] / svx / source / dialog / imapdlg.cxx
blob9cf1e4cb46428de1cae8903d313d28e2ce40e3a9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imapdlg.cxx,v $
10 * $Revision: 1.36 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define _SDR_NOITEMS
35 #define _SDR_NOTOUCH
36 #define _SDR_NOTRANSFORM
37 #define _SDR_NOOBJECTS
38 #define _SDR_NOVIEWMARKER
39 #define _SDR_NODRAGMETHODS
40 #define _SDR_NOUNDO
41 #define _SDR_NOXOUTDEV
43 #include <stdlib.h>
44 #include <tools/shl.hxx>
45 #ifndef _EINF_HXX
46 #include <tools/errinf.hxx>
47 #endif
48 #include <tools/urlobj.hxx>
49 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
50 #include <unotools/ucbstreamhelper.hxx>
51 #endif
52 #include <vcl/msgbox.hxx>
53 #include <vcl/group.hxx>
54 #include <vcl/lstbox.hxx>
55 #include <svtools/eitem.hxx>
56 #include <svtools/pathoptions.hxx>
57 #include <sfx2/dispatch.hxx>
58 #include <sfx2/module.hxx>
59 #include <sfx2/filedlghelper.hxx>
60 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
61 #include <svtools/urihelper.hxx>
62 #include <svtools/miscopt.hxx>
63 #include <svtools/ehdl.hxx>
64 #include <svtools/sfxecode.hxx>
65 #include <sfx2/viewfrm.hxx>
66 #include <sfx2/objsh.hxx>
67 #include <sfx2/docfile.hxx>
68 #include <unotools/localedatawrapper.hxx>
69 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
70 #include <comphelper/processfactory.hxx>
71 #endif
73 #define _IMAPDLG_PRIVATE
74 #include "imapdlg.hxx"
76 #include <svx/dialmgr.hxx>
77 #include <svx/dialogs.hrc>
78 #include <svx/svxids.hrc>
79 #include "imapdlg.hrc"
80 #include "imapwnd.hxx"
81 #include "imapimp.hxx"
82 #include "dlgutil.hxx"
83 #include <svx/svdtrans.hxx>
84 #include <svx/svdopath.hxx>
85 #include <vcl/svapp.hxx>
87 #define SELF_TARGET "_self"
88 #define IMAP_ALL_FILTER "<Alle>"
89 #define IMAP_CERN_FILTER "MAP - CERN"
90 #define IMAP_NCSA_FILTER "MAP - NCSA"
91 #define IMAP_BINARY_FILTER "SIP - StarView ImageMap"
92 #define IMAP_ALL_TYPE "*.*"
93 #define IMAP_BINARY_TYPE "*.sip"
94 #define IMAP_CERN_TYPE "*.map"
95 #define IMAP_NCSA_TYPE "*.map"
96 #define IMAP_BINARY_EXT "sip"
97 #define IMAP_CERN_EXT "map"
98 #define IMAP_NCSA_EXT "map"
100 /******************************************************************************/
102 SFX_IMPL_MODELESSDIALOG( SvxIMapDlgChildWindow, SID_IMAP );
104 /******************************************************************************/
106 inline String GetUnitString( long nVal_100, FieldUnit eFieldUnit, sal_Unicode cSep )
108 String aVal = UniString::CreateFromInt64( MetricField::ConvertValue( nVal_100, 2, MAP_100TH_MM, eFieldUnit ) );
110 while( aVal.Len() < 3 )
111 aVal.Insert( sal_Unicode('0'), 0 );
113 aVal.Insert( cSep, aVal.Len() - 2 );
114 aVal += sal_Unicode(' ');
115 aVal += SdrFormatter::GetUnitStr( eFieldUnit );
117 return aVal;
120 /*************************************************************************
122 |* ControllerItem
124 \************************************************************************/
126 SvxIMapDlgItem::SvxIMapDlgItem( USHORT _nId, SvxIMapDlg& rIMapDlg, SfxBindings& rBindings ) :
127 SfxControllerItem ( _nId, rBindings ),
128 rIMap ( rIMapDlg )
132 /*************************************************************************
134 |* StateChanged-Methode
136 \************************************************************************/
138 void SvxIMapDlgItem::StateChanged( USHORT nSID, SfxItemState /*eState*/,
139 const SfxPoolItem* pItem )
141 if ( ( nSID == SID_IMAP_EXEC ) && pItem )
143 const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
145 DBG_ASSERT( pStateItem || pItem == 0, "SfxBoolItem erwartet");
147 // Float ggf. disablen
148 rIMap.SetExecState( !pStateItem->GetValue() );
152 /*************************************************************************
156 \************************************************************************/
158 SvxIMapDlgChildWindow::SvxIMapDlgChildWindow( Window* _pParent, USHORT nId,
159 SfxBindings* pBindings,
160 SfxChildWinInfo* pInfo ) :
161 SfxChildWindow( _pParent, nId )
163 pWindow = new SvxIMapDlg( pBindings, this, _pParent, SVX_RES( RID_SVXDLG_IMAP ) );
164 SvxIMapDlg* pDlg = (SvxIMapDlg*) pWindow;
166 if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
167 pDlg->RollUp();
169 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
171 pDlg->Initialize( pInfo );
175 /*************************************************************************
179 \************************************************************************/
181 void SvxIMapDlgChildWindow::UpdateIMapDlg( const Graphic& rGraphic, const ImageMap* pImageMap,
182 const TargetList* pTargetList, void* pEditingObj )
184 if ( SfxViewFrame::Current() &&
185 SfxViewFrame::Current()->HasChildWindow( SvxIMapDlgChildWindow::GetChildWindowId() ) )
186 SVXIMAPDLG()->Update( rGraphic, pImageMap, pTargetList, pEditingObj );
190 /*************************************************************************
194 \************************************************************************/
196 SvxIMapDlg::SvxIMapDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
197 Window* _pParent, const ResId& rResId ) :
198 SfxModelessDialog ( _pBindings, pCW, _pParent, rResId ),
200 aTbxIMapDlg1 ( this, SVX_RES( TBX_IMAPDLG1 ) ),
201 aFtURL ( this, SVX_RES( FT_URL ) ),
202 maURLBox ( this, SVX_RES( CBB_URL ) ),
203 aFtText ( this, SVX_RES( FT_TEXT ) ),
204 aEdtText ( this, SVX_RES( EDT_TEXT ) ),
205 maFtTarget ( this, SVX_RES( RID_SVXCTL_FT_TARGET ) ),
206 maCbbTarget ( this, SVX_RES( RID_SVXCTL_CBB_TARGET ) ),
207 aStbStatus ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
208 maImageList ( SVX_RES( IL_IMAPDLG ) ),
209 maImageListH ( SVX_RES( ILH_IMAPDLG ) ),
210 pCheckObj ( NULL ),
211 aIMapItem ( SID_IMAP_EXEC, *this, *_pBindings )
213 pIMapWnd = new IMapWindow( this, SVX_RES( RID_SVXCTL_IMAP ), _pBindings->GetActiveFrame() );
215 ApplyImageList();
217 FreeResource();
219 pOwnData = new IMapOwnData( this );
221 pIMapWnd->SetInfoLink( LINK( this, SvxIMapDlg, InfoHdl ) );
222 pIMapWnd->SetMousePosLink( LINK( this, SvxIMapDlg, MousePosHdl ) );
223 pIMapWnd->SetGraphSizeLink( LINK( this, SvxIMapDlg, GraphSizeHdl ) );
224 pIMapWnd->SetUpdateLink( LINK( this, SvxIMapDlg, StateHdl ) );
226 maURLBox.SetModifyHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
227 maURLBox.SetSelectHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
228 maURLBox.SetLoseFocusHdl( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
229 aEdtText.SetModifyHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
230 maCbbTarget.SetLoseFocusHdl( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
232 SvtMiscOptions aMiscOptions;
233 aMiscOptions.AddListener( LINK( this, SvxIMapDlg, MiscHdl ) );
235 aTbxIMapDlg1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
236 aTbxIMapDlg1.SetSizePixel( aTbxIMapDlg1.CalcWindowSizePixel() );
237 aTbxIMapDlg1.SetSelectHdl( LINK( this, SvxIMapDlg, TbxClickHdl ) );
238 aTbxIMapDlg1.CheckItem( TBI_SELECT, TRUE );
239 TbxClickHdl( &aTbxIMapDlg1 );
241 SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
243 aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
244 aStbStatus.InsertItem( 2, 10 + GetTextWidth( DEFINE_CONST_UNICODE( " 9999,99 cm / 9999,99 cm ") ), SIB_CENTER | SIB_IN );
245 aStbStatus.InsertItem( 3, 10 + GetTextWidth( DEFINE_CONST_UNICODE( " 9999,99 cm x 9999,99 cm ") ), SIB_CENTER | SIB_IN );
247 aFtURL.Disable();
248 maURLBox.Disable();
249 aFtText.Disable();
250 aEdtText.Disable();
251 maFtTarget.Disable();
252 maCbbTarget.Disable();
253 pOwnData->bExecState = FALSE;
255 Resize();
257 pOwnData->aTimer.SetTimeout( 100 );
258 pOwnData->aTimer.SetTimeoutHdl( LINK( this, SvxIMapDlg, UpdateHdl ) );
260 aTbxIMapDlg1.EnableItem( TBI_ACTIVE, FALSE );
261 aTbxIMapDlg1.EnableItem( TBI_MACRO, FALSE );
262 aTbxIMapDlg1.EnableItem( TBI_PROPERTY, FALSE );
266 /*************************************************************************
268 |* Dtor
270 \************************************************************************/
272 SvxIMapDlg::~SvxIMapDlg()
274 // URL-Liste loeschen
275 delete pIMapWnd;
276 delete pOwnData;
280 /*************************************************************************
282 |* Resize-Methode
284 \************************************************************************/
286 void SvxIMapDlg::Resize()
288 SfxModelessDialog::Resize();
290 Size aMinSize( GetMinOutputSizePixel() );
291 Size aNewSize( GetOutputSizePixel() );
293 if ( aNewSize.Height() >= aMinSize.Height() )
295 Size _aSize( aStbStatus.GetSizePixel() );
296 Point aPoint( 0, aNewSize.Height() - _aSize.Height() );
298 // StatusBar positionieren
299 aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
300 aStbStatus.Show();
302 // EditWindow positionieren
303 _aSize.Width() = aNewSize.Width() - 18;
304 _aSize.Height() = aPoint.Y() - pIMapWnd->GetPosPixel().Y() - 6;
305 pIMapWnd->SetSizePixel( _aSize );
307 aLastSize = aNewSize;
312 /*************************************************************************
314 |* Close-Methode
316 \************************************************************************/
318 BOOL SvxIMapDlg::Close()
320 BOOL bRet = TRUE;
322 if ( aTbxIMapDlg1.IsItemEnabled( TBI_APPLY ) )
324 QueryBox aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
325 String( SVX_RES( STR_IMAPDLG_MODIFY ) ) );
326 const long nRet = aQBox.Execute();
328 if( nRet == RET_YES )
330 SfxBoolItem aBoolItem( SID_IMAP_EXEC, TRUE );
331 GetBindings().GetDispatcher()->Execute(
332 SID_IMAP_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
334 else if( nRet == RET_CANCEL )
335 bRet = FALSE;
337 else if( pIMapWnd->IsChanged() )
339 QueryBox aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
340 String( SVX_RES( STR_IMAPDLG_SAVE ) ) );
341 const long nRet = aQBox.Execute();
343 if( nRet == RET_YES )
344 bRet = DoSave();
345 else if( nRet == RET_CANCEL )
346 bRet = FALSE;
349 return( bRet ? SfxModelessDialog::Close() : FALSE );
353 /*************************************************************************
355 |* Enabled oder disabled alle Controls
357 \************************************************************************/
359 void SvxIMapDlg::SetExecState( BOOL bEnable )
361 pOwnData->bExecState = bEnable;
365 /*************************************************************************
369 \************************************************************************/
371 void SvxIMapDlg::SetGraphic( const Graphic& rGraphic )
373 pIMapWnd->SetGraphic( rGraphic );
377 /*************************************************************************
381 \************************************************************************/
383 void SvxIMapDlg::SetImageMap( const ImageMap& rImageMap )
385 pIMapWnd->SetImageMap( rImageMap );
389 /*************************************************************************
393 \************************************************************************/
395 const ImageMap& SvxIMapDlg::GetImageMap() const
397 return pIMapWnd->GetImageMap();
401 /*************************************************************************
405 \************************************************************************/
407 void SvxIMapDlg::SetTargetList( const TargetList& rTargetList )
409 TargetList aNewList( rTargetList );
411 pIMapWnd->SetTargetList( aNewList );
413 maCbbTarget.Clear();
415 for( String* pStr = aNewList.First(); pStr; pStr = aNewList.Next() )
416 maCbbTarget.InsertEntry( *pStr );
420 /*************************************************************************
424 \************************************************************************/
426 const TargetList& SvxIMapDlg::GetTargetList() const
428 return pIMapWnd->GetTargetList();
432 /*************************************************************************
436 \************************************************************************/
438 void SvxIMapDlg::Update( const Graphic& rGraphic, const ImageMap* pImageMap,
439 const TargetList* pTargetList, void* pEditingObj )
441 pOwnData->aUpdateGraphic = rGraphic;
443 if ( pImageMap )
444 pOwnData->aUpdateImageMap = *pImageMap;
445 else
446 pOwnData->aUpdateImageMap.ClearImageMap();
448 pOwnData->pUpdateEditingObject = pEditingObj;
450 // UpdateTargetList loeschen, da diese Methode
451 // vor dem Zuschlagen des Update-Timers noch
452 // mehrmals gerufen werden kann( #46540 )
453 for( String* pStr = pOwnData->aUpdateTargetList.First(); pStr; pStr = pOwnData->aUpdateTargetList.Next() )
454 delete pStr;
455 pOwnData->aUpdateTargetList.Clear();
457 // TargetListe muss kopiert werden, da sie im
458 // Besitz des Aufrufers ist und von ihm nach diesem
459 // Aufruf sofort geloescht werden kann;
460 // die kopierte Liste wird im Handler wieder geloescht
461 if( pTargetList )
463 TargetList aTargetList( *pTargetList );
465 for( String* pStr = aTargetList.First(); pStr; pStr = aTargetList.Next() )
466 pOwnData->aUpdateTargetList.Insert( new String( *pStr ) );
469 pOwnData->aTimer.Start();
473 void SvxIMapDlg::KeyInput( const KeyEvent& rKEvt )
475 SfxModelessDialog::KeyInput( rKEvt );
478 /*************************************************************************
480 |* Click-Hdl fuer ToolBox
482 \************************************************************************/
484 IMPL_LINK( SvxIMapDlg, TbxClickHdl, ToolBox*, pTbx )
486 USHORT nNewItemId = pTbx->GetCurItemId();
488 switch( pTbx->GetCurItemId() )
490 case( TBI_APPLY ):
492 URLLoseFocusHdl( NULL );
493 SfxBoolItem aBoolItem( SID_IMAP_EXEC, TRUE );
494 GetBindings().GetDispatcher()->Execute(
495 SID_IMAP_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
497 break;
499 case( TBI_OPEN ):
500 DoOpen();
501 break;
503 case( TBI_SAVEAS ):
504 DoSave();
505 break;
507 case( TBI_SELECT ):
509 pTbx->CheckItem( nNewItemId, TRUE );
510 pIMapWnd->SetEditMode( TRUE );
511 if( pTbx->IsKeyEvent() )
513 if((pTbx->GetKeyModifier() & KEY_MOD1) != 0)
514 pIMapWnd->SelectFirstObject();
515 else
516 pIMapWnd->GrabFocus();
519 break;
521 case( TBI_RECT ):
523 pTbx->CheckItem( nNewItemId, TRUE );
524 pIMapWnd->SetObjKind( OBJ_RECT );
525 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
527 pIMapWnd->CreateDefaultObject();
528 pIMapWnd->GrabFocus();
531 break;
533 case( TBI_CIRCLE ):
535 pTbx->CheckItem( nNewItemId, TRUE );
536 pIMapWnd->SetObjKind( OBJ_CIRC );
537 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
539 pIMapWnd->CreateDefaultObject();
540 pIMapWnd->GrabFocus();
543 break;
545 case( TBI_POLY ):
547 pTbx->CheckItem( nNewItemId, TRUE );
548 pIMapWnd->SetObjKind( OBJ_POLY );
549 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
551 pIMapWnd->CreateDefaultObject();
552 pIMapWnd->GrabFocus();
555 break;
557 case( TBI_FREEPOLY ):
559 pTbx->CheckItem( nNewItemId, TRUE );
560 pIMapWnd->SetObjKind( OBJ_FREEFILL );
561 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
563 pIMapWnd->CreateDefaultObject();
564 pIMapWnd->GrabFocus();
567 break;
569 case( TBI_ACTIVE ):
571 URLLoseFocusHdl( NULL );
572 BOOL bNewState = !pTbx->IsItemChecked( TBI_ACTIVE );
573 pTbx->CheckItem( TBI_ACTIVE, bNewState );
574 pIMapWnd->SetCurrentObjState( !bNewState );
576 break;
578 case( TBI_MACRO ):
579 pIMapWnd->DoMacroAssign();
580 break;
582 case( TBI_PROPERTY ):
583 pIMapWnd->DoPropertyDialog();
584 break;
586 case( TBI_POLYEDIT ):
587 pIMapWnd->SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
588 if( pTbx->IsKeyEvent() && pTbx->IsItemChecked( TBI_POLYEDIT ) )
589 pIMapWnd->StartPolyEdit();
590 break;
592 case( TBI_POLYMOVE ):
593 pIMapWnd->SetPolyEditMode( SID_BEZIER_MOVE );
594 break;
596 case( TBI_POLYINSERT ):
597 pIMapWnd->SetPolyEditMode( SID_BEZIER_INSERT );
598 break;
600 case( TBI_POLYDELETE ):
601 pIMapWnd->GetSdrView()->DeleteMarkedPoints();
602 break;
604 case( TBI_UNDO ):
606 URLLoseFocusHdl( NULL );
607 pIMapWnd->GetSdrModel()->Undo();
609 break;
611 case( TBI_REDO ):
613 URLLoseFocusHdl( NULL );
614 pIMapWnd->GetSdrModel()->Redo();
616 break;
618 default:
619 break;
622 return 0;
626 /*************************************************************************
630 \************************************************************************/
632 void SvxIMapDlg::DoOpen()
634 ::sfx2::FileDialogHelper aDlg(
635 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
637 ImageMap aLoadIMap;
638 const String aFilter( DEFINE_CONST_UNICODE( IMAP_ALL_FILTER ) );
640 aDlg.AddFilter( aFilter, DEFINE_CONST_UNICODE( IMAP_ALL_TYPE ) );
641 aDlg.AddFilter( DEFINE_CONST_UNICODE( IMAP_CERN_FILTER ), DEFINE_CONST_UNICODE( IMAP_CERN_TYPE ) );
642 aDlg.AddFilter( DEFINE_CONST_UNICODE( IMAP_NCSA_FILTER ), DEFINE_CONST_UNICODE( IMAP_NCSA_TYPE ) );
643 aDlg.AddFilter( DEFINE_CONST_UNICODE( IMAP_BINARY_FILTER ), DEFINE_CONST_UNICODE( IMAP_BINARY_TYPE ) );
645 aDlg.SetCurrentFilter( aFilter );
646 aDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
648 if( aDlg.Execute() == ERRCODE_NONE )
650 INetURLObject aURL( aDlg.GetPath() );
651 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
652 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
654 if( pIStm )
656 aLoadIMap.Read( *pIStm, IMAP_FORMAT_DETECT, String() );
658 if( pIStm->GetError() )
660 SfxErrorContext eEC(ERRCODE_SFX_GENERAL,this);
661 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
663 else
664 pIMapWnd->SetImageMap( aLoadIMap );
666 delete pIStm;
669 pIMapWnd->Invalidate();
674 /*************************************************************************
678 \************************************************************************/
680 BOOL SvxIMapDlg::DoSave()
682 ::sfx2::FileDialogHelper aDlg(
683 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
685 const String aBinFilter( DEFINE_CONST_UNICODE( IMAP_BINARY_FILTER ) );
686 const String aCERNFilter( DEFINE_CONST_UNICODE( IMAP_CERN_FILTER ) );
687 const String aNCSAFilter( DEFINE_CONST_UNICODE( IMAP_NCSA_FILTER ) );
688 SdrModel* pModel = pIMapWnd->GetSdrModel();
689 const sal_Bool bChanged = pModel->IsChanged();
690 BOOL bRet = false;
692 aDlg.AddFilter( aCERNFilter, DEFINE_CONST_UNICODE( IMAP_CERN_TYPE ) );
693 aDlg.AddFilter( aNCSAFilter, DEFINE_CONST_UNICODE( IMAP_NCSA_TYPE ) );
694 aDlg.AddFilter( aBinFilter, DEFINE_CONST_UNICODE( IMAP_BINARY_TYPE ) );
696 aDlg.SetCurrentFilter( aCERNFilter );
697 aDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
699 if( aDlg.Execute() == ERRCODE_NONE )
701 const String aFilter( aDlg.GetCurrentFilter() );
702 String aExt;
703 ULONG nFormat;
705 if ( aFilter == aBinFilter )
707 nFormat = IMAP_FORMAT_BIN;
708 aExt = DEFINE_CONST_UNICODE( IMAP_BINARY_EXT );
710 else if ( aFilter == aCERNFilter )
712 nFormat = IMAP_FORMAT_CERN;
713 aExt = DEFINE_CONST_UNICODE( IMAP_CERN_EXT );
715 else if ( aFilter == aNCSAFilter )
717 nFormat = IMAP_FORMAT_NCSA;
718 aExt = DEFINE_CONST_UNICODE( IMAP_NCSA_EXT );
720 else
722 return FALSE;
725 INetURLObject aURL( aDlg.GetPath() );
727 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
729 DBG_ERROR( "invalid URL" );
731 else
733 if( !aURL.getExtension().getLength() )
734 aURL.setExtension( aExt );
736 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
737 if( pOStm )
739 pIMapWnd->GetImageMap().Write( *pOStm, nFormat, String() );
741 if( pOStm->GetError() )
742 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
744 delete pOStm;
745 pModel->SetChanged( bChanged );
746 bRet = TRUE;
751 return bRet;
755 /*************************************************************************
759 \************************************************************************/
761 IMPL_LINK( SvxIMapDlg, InfoHdl, IMapWindow*, pWnd )
763 String aStr;
764 const NotifyInfo& rInfo = pWnd->GetInfo();
766 if ( rInfo.bNewObj )
768 if( rInfo.aMarkURL.Len() && ( maURLBox.GetEntryPos( rInfo.aMarkURL ) == LISTBOX_ENTRY_NOTFOUND ) )
769 maURLBox.InsertEntry( rInfo.aMarkURL );
771 maURLBox.SetText( rInfo.aMarkURL );
772 aEdtText.SetText( rInfo.aMarkAltText );
774 if ( !rInfo.aMarkTarget.Len() )
775 maCbbTarget.SetText( DEFINE_CONST_UNICODE( SELF_TARGET ) );
776 else
777 maCbbTarget.SetText( rInfo.aMarkTarget );
780 if ( !rInfo.bOneMarked )
782 aTbxIMapDlg1.CheckItem( TBI_ACTIVE, FALSE );
783 aTbxIMapDlg1.EnableItem( TBI_ACTIVE, FALSE );
784 aTbxIMapDlg1.EnableItem( TBI_MACRO, FALSE );
785 aTbxIMapDlg1.EnableItem( TBI_PROPERTY, FALSE );
786 aStbStatus.SetItemText( 1, aStr );
788 aFtURL.Disable();
789 maURLBox.Disable();
790 aFtText.Disable();
791 aEdtText.Disable();
792 maFtTarget.Disable();
793 maCbbTarget.Disable();
795 maURLBox.SetText( String() );
796 aEdtText.SetText( String() );
798 else
800 aTbxIMapDlg1.EnableItem( TBI_ACTIVE, TRUE );
801 aTbxIMapDlg1.CheckItem( TBI_ACTIVE, !rInfo.bActivated );
802 aTbxIMapDlg1.EnableItem( TBI_MACRO, TRUE );
803 aTbxIMapDlg1.EnableItem( TBI_PROPERTY, TRUE );
805 aFtURL.Enable();
806 maURLBox.Enable();
807 aFtText.Enable();
808 aEdtText.Enable();
809 maFtTarget.Enable();
810 maCbbTarget.Enable();
812 aStbStatus.SetItemText( 1, rInfo.aMarkURL );
814 if ( maURLBox.GetText() != rInfo.aMarkURL )
815 maURLBox.SetText( rInfo.aMarkURL );
817 if ( aEdtText.GetText() != rInfo.aMarkAltText )
818 aEdtText.SetText( rInfo.aMarkAltText );
820 if ( !rInfo.aMarkTarget.Len() )
821 maCbbTarget.SetText( DEFINE_CONST_UNICODE( SELF_TARGET ) );
822 else
823 maCbbTarget.SetText( rInfo.aMarkTarget );
826 return 0;
829 /*************************************************************************
833 \************************************************************************/
835 IMPL_LINK( SvxIMapDlg, MousePosHdl, IMapWindow*, pWnd )
837 String aStr;
838 const FieldUnit eFieldUnit = GetModuleFieldUnit();
839 const Point& rMousePos = pWnd->GetMousePos();
840 LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
841 const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
843 aStr.Assign( GetUnitString( rMousePos.X(), eFieldUnit, cSep ) );
844 aStr.Append( DEFINE_CONST_UNICODE( " / " ) );
845 aStr.Append( GetUnitString( rMousePos.Y(), eFieldUnit, cSep ) );
847 aStbStatus.SetItemText( 2, aStr );
849 return 0L;
852 /*************************************************************************
856 \************************************************************************/
858 IMPL_LINK( SvxIMapDlg, GraphSizeHdl, IMapWindow*, pWnd )
860 String aStr;
861 const FieldUnit eFieldUnit = GetModuleFieldUnit();
862 const Size& rSize = pWnd->GetGraphicSize();
863 LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
864 const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
866 aStr.Assign( GetUnitString( rSize.Width(), eFieldUnit, cSep ) );
867 aStr.Append( DEFINE_CONST_UNICODE( " x " ) );
868 aStr.Append( GetUnitString( rSize.Height(), eFieldUnit, cSep ) );
870 aStbStatus.SetItemText( 3, aStr );
872 return 0L;
875 /*************************************************************************
879 \************************************************************************/
881 IMPL_LINK( SvxIMapDlg, URLModifyHdl, void*, EMPTYARG )
883 NotifyInfo aNewInfo;
885 aNewInfo.aMarkURL = maURLBox.GetText();
886 aNewInfo.aMarkAltText = aEdtText.GetText();
887 aNewInfo.aMarkTarget = maCbbTarget.GetText();
889 pIMapWnd->ReplaceActualIMapInfo( aNewInfo );
891 return 0;
895 /*************************************************************************
899 \************************************************************************/
901 IMPL_LINK( SvxIMapDlg, URLLoseFocusHdl, void*, EMPTYARG )
903 NotifyInfo aNewInfo;
904 const String aURLText( maURLBox.GetText() );
905 const String aTargetText( maCbbTarget.GetText() );
907 if ( aURLText.Len() )
909 String aBase = GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
910 aNewInfo.aMarkURL = ::URIHelper::SmartRel2Abs( INetURLObject(aBase), aURLText, URIHelper::GetMaybeFileHdl(), true, false,
911 INetURLObject::WAS_ENCODED,
912 INetURLObject::DECODE_UNAMBIGUOUS );
914 else
915 aNewInfo.aMarkURL = aURLText;
917 aNewInfo.aMarkAltText = aEdtText.GetText();
919 if ( !aTargetText.Len() )
920 aNewInfo.aMarkTarget = DEFINE_CONST_UNICODE( SELF_TARGET );
921 else
922 aNewInfo.aMarkTarget = aTargetText;
924 pIMapWnd->ReplaceActualIMapInfo( aNewInfo );
926 return 0;
930 /*************************************************************************
934 \************************************************************************/
936 IMPL_LINK( SvxIMapDlg, UpdateHdl, Timer*, EMPTYARG )
938 pOwnData->aTimer.Stop();
940 if ( pOwnData->pUpdateEditingObject != pCheckObj )
942 if ( pIMapWnd->IsChanged() &&
943 ( QueryBox( this, WB_YES_NO | WB_DEF_YES,
944 String( SVX_RES( STR_IMAPDLG_SAVE ) ) ).Execute() == RET_YES ) )
946 DoSave();
949 SetGraphic( pOwnData->aUpdateGraphic );
950 SetImageMap( pOwnData->aUpdateImageMap );
951 SetTargetList( pOwnData->aUpdateTargetList );
952 SetEditingObject( pOwnData->pUpdateEditingObject );
954 // Nach Wechsel => default Selektion
955 aTbxIMapDlg1.CheckItem( TBI_SELECT, TRUE );
956 pIMapWnd->SetEditMode( TRUE );
959 // die in der Update-Methode kopierte Liste wieder loeschen
960 for( String* pStr = pOwnData->aUpdateTargetList.First(); pStr; pStr = pOwnData->aUpdateTargetList.Next() )
961 delete pStr;
963 pOwnData->aUpdateTargetList.Clear();
965 GetBindings().Invalidate( SID_IMAP_EXEC );
967 return 0L;
971 /*************************************************************************
975 \************************************************************************/
977 IMPL_LINK( SvxIMapDlg, StateHdl, IMapWindow*, pWnd )
979 const SdrObject* pObj = pWnd->GetSelectedSdrObject();
980 const SdrModel* pModel = pWnd->GetSdrModel();
981 const SdrView* pView = pWnd->GetSdrView();
982 const BOOL bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
983 const BOOL bDrawEnabled = !( bPolyEdit && aTbxIMapDlg1.IsItemChecked( TBI_POLYEDIT ) );
985 aTbxIMapDlg1.EnableItem( TBI_APPLY, pOwnData->bExecState && pWnd->IsChanged() );
987 aTbxIMapDlg1.EnableItem( TBI_SELECT, bDrawEnabled );
988 aTbxIMapDlg1.EnableItem( TBI_RECT, bDrawEnabled );
989 aTbxIMapDlg1.EnableItem( TBI_CIRCLE, bDrawEnabled );
990 aTbxIMapDlg1.EnableItem( TBI_POLY, bDrawEnabled );
991 aTbxIMapDlg1.EnableItem( TBI_FREEPOLY, bDrawEnabled );
993 // BezierEditor-Stati
994 aTbxIMapDlg1.EnableItem( TBI_POLYEDIT, bPolyEdit );
995 aTbxIMapDlg1.EnableItem( TBI_POLYMOVE, !bDrawEnabled );
996 aTbxIMapDlg1.EnableItem( TBI_POLYINSERT, !bDrawEnabled );
997 aTbxIMapDlg1.EnableItem( TBI_POLYDELETE, !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
999 // Undo/Redo
1000 aTbxIMapDlg1.EnableItem( TBI_UNDO, pModel->GetUndoActionCount() > 0 );
1001 aTbxIMapDlg1.EnableItem( TBI_REDO, pModel->GetRedoActionCount() > 0 );
1003 if ( bPolyEdit )
1005 USHORT nId = 0;
1007 switch( pWnd->GetPolyEditMode() )
1009 case( SID_BEZIER_MOVE ): nId = TBI_POLYMOVE; break;
1010 case( SID_BEZIER_INSERT ): nId = TBI_POLYINSERT; break;
1012 default:
1013 break;
1016 aTbxIMapDlg1.CheckItem( nId, TRUE );
1018 else
1020 aTbxIMapDlg1.CheckItem( TBI_POLYEDIT, FALSE );
1021 aTbxIMapDlg1.CheckItem( TBI_POLYMOVE, TRUE );
1022 aTbxIMapDlg1.CheckItem( TBI_POLYINSERT, FALSE );
1023 pWnd->SetPolyEditMode( 0 );
1026 return 0L;
1029 /*************************************************************************
1033 \************************************************************************/
1035 IMPL_LINK( SvxIMapDlg, MiscHdl, void*, EMPTYARG )
1037 SvtMiscOptions aMiscOptions;
1038 aTbxIMapDlg1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
1040 return 0L;
1043 void SvxIMapDlg::ApplyImageList()
1045 bool bHighContrast = GetDisplayBackground().GetColor().IsDark() != 0;
1047 ImageList& rImgLst = bHighContrast ? maImageListH : maImageList;
1049 aTbxIMapDlg1.SetImageList( rImgLst );
1052 void SvxIMapDlg::DataChanged( const DataChangedEvent& rDCEvt )
1054 SfxModelessDialog::DataChanged( rDCEvt );
1056 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1057 ApplyImageList();