Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / dialog / imapdlg.cxx
blobf062407868956c635b702a45003a1386bd7b1dbe
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 <stdlib.h>
21 #include <tools/shl.hxx>
22 #include <tools/errinf.hxx>
23 #include <tools/urlobj.hxx>
24 #include <unotools/ucbstreamhelper.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <vcl/group.hxx>
27 #include <vcl/lstbox.hxx>
28 #include <svl/eitem.hxx>
29 #include <unotools/pathoptions.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/module.hxx>
32 #include <sfx2/filedlghelper.hxx>
33 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
34 #include <svl/urihelper.hxx>
35 #include <svtools/miscopt.hxx>
36 #include <svtools/ehdl.hxx>
37 #include <svtools/sfxecode.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <unotools/localedatawrapper.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <vcl/layout.hxx>
44 #include <svx/imapdlg.hxx>
45 #include <svx/dialmgr.hxx>
46 #include <svx/dialogs.hrc>
47 #include <svx/svxids.hrc>
48 #include "imapdlg.hrc"
49 #include "imapwnd.hxx"
50 #include "imapimp.hxx"
51 #include "svx/dlgutil.hxx"
52 #include <svx/svdtrans.hxx>
53 #include <svx/svdopath.hxx>
54 #include <vcl/svapp.hxx>
55 #include <vcl/settings.hxx>
56 #include "dlgunit.hxx"
58 #define SELF_TARGET "_self"
59 #define IMAP_ALL_FILTER OUString("<Alle>")
60 #define IMAP_CERN_FILTER OUString("MAP - CERN")
61 #define IMAP_NCSA_FILTER OUString("MAP - NCSA")
62 #define IMAP_BINARY_FILTER OUString("SIP - StarView ImageMap")
63 #define IMAP_ALL_TYPE OUString("*.*")
64 #define IMAP_BINARY_TYPE OUString("*.sip")
65 #define IMAP_CERN_TYPE OUString("*.map")
66 #define IMAP_NCSA_TYPE OUString("*.map")
67 #define IMAP_BINARY_EXT OUString("sip")
68 #define IMAP_CERN_EXT OUString("map")
69 #define IMAP_NCSA_EXT OUString("map")
71 /******************************************************************************/
73 SFX_IMPL_MODELESSDIALOG_WITHID( SvxIMapDlgChildWindow, SID_IMAP );
75 // ControllerItem
77 SvxIMapDlgItem::SvxIMapDlgItem( sal_uInt16 _nId, SvxIMapDlg& rIMapDlg, SfxBindings& rBindings ) :
78 SfxControllerItem ( _nId, rBindings ),
79 rIMap ( rIMapDlg )
83 void SvxIMapDlgItem::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/,
84 const SfxPoolItem* pItem )
86 if ( ( nSID == SID_IMAP_EXEC ) && pItem )
88 const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
89 assert(pStateItem); //SfxBoolItem expected
90 if (pStateItem)
92 // Disable Float if possible
93 rIMap.SetExecState( !pStateItem->GetValue() );
98 SvxIMapDlgChildWindow::SvxIMapDlgChildWindow( Window* _pParent, sal_uInt16 nId,
99 SfxBindings* pBindings,
100 SfxChildWinInfo* pInfo ) :
101 SfxChildWindow( _pParent, nId )
103 pWindow = new SvxIMapDlg( pBindings, this, _pParent, SVX_RES( RID_SVXDLG_IMAP ) );
104 SvxIMapDlg* pDlg = (SvxIMapDlg*) pWindow;
106 if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
107 pDlg->RollUp();
109 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
111 pDlg->Initialize( pInfo );
114 void SvxIMapDlgChildWindow::UpdateIMapDlg( const Graphic& rGraphic, const ImageMap* pImageMap,
115 const TargetList* pTargetList, void* pEditingObj )
117 if ( SfxViewFrame::Current() &&
118 SfxViewFrame::Current()->HasChildWindow( SvxIMapDlgChildWindow::GetChildWindowId() ) )
119 SVXIMAPDLG()->UpdateLink( rGraphic, pImageMap, pTargetList, pEditingObj );
122 SvxIMapDlg::SvxIMapDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
123 Window* _pParent, const ResId& rResId ) :
124 SfxModelessDialog ( _pBindings, pCW, _pParent, rResId ),
126 aTbxIMapDlg1 ( this, SVX_RES( TBX_IMAPDLG1 ) ),
127 aFtURL ( this, SVX_RES( FT_URL ) ),
128 maURLBox ( this, SVX_RES( CBB_URL ) ),
129 aFtText ( this, SVX_RES( FT_TEXT ) ),
130 aEdtText ( this, SVX_RES( EDT_TEXT ) ),
131 maFtTarget ( this, SVX_RES( RID_SVXCTL_FT_TARGET ) ),
132 maCbbTarget ( this, SVX_RES( RID_SVXCTL_CBB_TARGET ) ),
133 aStbStatus ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
134 maImageList ( SVX_RES( IL_IMAPDLG ) ),
135 pCheckObj ( NULL ),
136 aIMapItem ( SID_IMAP_EXEC, *this, *_pBindings )
138 pIMapWnd = new IMapWindow( this, SVX_RES( RID_SVXCTL_IMAP ), _pBindings->GetActiveFrame() );
140 ApplyImageList();
142 FreeResource();
144 pOwnData = new IMapOwnData;
146 pIMapWnd->SetInfoLink( LINK( this, SvxIMapDlg, InfoHdl ) );
147 pIMapWnd->SetMousePosLink( LINK( this, SvxIMapDlg, MousePosHdl ) );
148 pIMapWnd->SetGraphSizeLink( LINK( this, SvxIMapDlg, GraphSizeHdl ) );
149 pIMapWnd->SetUpdateLink( LINK( this, SvxIMapDlg, StateHdl ) );
151 maURLBox.SetModifyHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
152 maURLBox.SetSelectHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
153 maURLBox.SetLoseFocusHdl( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
154 aEdtText.SetModifyHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
155 maCbbTarget.SetLoseFocusHdl( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
157 SvtMiscOptions aMiscOptions;
158 aMiscOptions.AddListenerLink( LINK( this, SvxIMapDlg, MiscHdl ) );
160 aTbxIMapDlg1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
161 aTbxIMapDlg1.SetSizePixel( aTbxIMapDlg1.CalcWindowSizePixel() );
162 aTbxIMapDlg1.SetSelectHdl( LINK( this, SvxIMapDlg, TbxClickHdl ) );
163 aTbxIMapDlg1.CheckItem( TBI_SELECT, true );
164 TbxClickHdl( &aTbxIMapDlg1 );
166 SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
168 aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
169 aStbStatus.InsertItem( 2, 10 + GetTextWidth( OUString(" 9999,99 cm / 9999,99 cm ") ), SIB_CENTER | SIB_IN );
170 aStbStatus.InsertItem( 3, 10 + GetTextWidth( OUString(" 9999,99 cm x 9999,99 cm ") ), SIB_CENTER | SIB_IN );
172 aFtURL.Disable();
173 maURLBox.Disable();
174 aFtText.Disable();
175 aEdtText.Disable();
176 maFtTarget.Disable();
177 maCbbTarget.Disable();
178 pOwnData->bExecState = false;
180 Resize();
182 pOwnData->aTimer.SetTimeout( 100 );
183 pOwnData->aTimer.SetTimeoutHdl( LINK( this, SvxIMapDlg, UpdateHdl ) );
185 aTbxIMapDlg1.EnableItem( TBI_ACTIVE, false );
186 aTbxIMapDlg1.EnableItem( TBI_MACRO, false );
187 aTbxIMapDlg1.EnableItem( TBI_PROPERTY, false );
190 SvxIMapDlg::~SvxIMapDlg()
192 // Delete URL-List
193 delete pIMapWnd;
194 delete pOwnData;
197 void SvxIMapDlg::Resize()
199 SfxModelessDialog::Resize();
201 Size aMinSize( GetMinOutputSizePixel() );
202 Size aNewSize( GetOutputSizePixel() );
204 if ( aNewSize.Height() >= aMinSize.Height() )
206 Size _aSize( aStbStatus.GetSizePixel() );
207 Point aPoint( 0, aNewSize.Height() - _aSize.Height() );
209 // Position the StatusBar
210 aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
211 aStbStatus.Show();
213 // Position the EditWindow
214 _aSize.Width() = aNewSize.Width() - 18;
215 _aSize.Height() = aPoint.Y() - pIMapWnd->GetPosPixel().Y() - 6;
216 pIMapWnd->SetSizePixel( _aSize );
218 aLastSize = aNewSize;
222 bool SvxIMapDlg::Close()
224 bool bRet = true;
226 if ( aTbxIMapDlg1.IsItemEnabled( TBI_APPLY ) )
228 MessageDialog aQBox( this,"QueryModifyImageMapChangesDialog","svx/ui/querymodifyimagemapchangesdialog.ui");
229 const long nRet = aQBox.Execute();
231 if( nRet == RET_YES )
233 SfxBoolItem aBoolItem( SID_IMAP_EXEC, true );
234 GetBindings().GetDispatcher()->Execute(
235 SID_IMAP_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
237 else if( nRet == RET_CANCEL )
238 bRet = false;
240 else if( pIMapWnd->IsChanged() )
242 MessageDialog aQBox( this,"QuerySaveImageMapChangesDialog","svx/ui/querysaveimagemapchangesdialog.ui");
243 const long nRet = aQBox.Execute();
245 if( nRet == RET_YES )
246 bRet = DoSave();
247 else if( nRet == RET_CANCEL )
248 bRet = false;
251 return( bRet ? SfxModelessDialog::Close() : sal_False );
254 // Enabled or disable all Controls
256 void SvxIMapDlg::SetExecState( bool bEnable )
258 pOwnData->bExecState = bEnable;
261 void SvxIMapDlg::SetGraphic( const Graphic& rGraphic )
263 pIMapWnd->SetGraphic( rGraphic );
266 void SvxIMapDlg::SetImageMap( const ImageMap& rImageMap )
268 pIMapWnd->SetImageMap( rImageMap );
271 const ImageMap& SvxIMapDlg::GetImageMap() const
273 return pIMapWnd->GetImageMap();
276 void SvxIMapDlg::SetTargetList( const TargetList& rTargetList )
278 TargetList aNewList( rTargetList );
280 pIMapWnd->SetTargetList( aNewList );
282 maCbbTarget.Clear();
284 for ( size_t i = 0, n = aNewList.size(); i < n; ++i )
285 maCbbTarget.InsertEntry( aNewList[ i ] );
288 void SvxIMapDlg::UpdateLink( const Graphic& rGraphic, const ImageMap* pImageMap,
289 const TargetList* pTargetList, void* pEditingObj )
291 pOwnData->aUpdateGraphic = rGraphic;
293 if ( pImageMap )
294 pOwnData->aUpdateImageMap = *pImageMap;
295 else
296 pOwnData->aUpdateImageMap.ClearImageMap();
298 pOwnData->pUpdateEditingObject = pEditingObj;
300 // Delete UpdateTargetList, because this method can still be called several
301 // times before the update timer is turned on
302 pOwnData->aUpdateTargetList.clear();
304 // TargetList must be copied, since it is owned by the caller and can be
305 // deleted immediately after this call the copied list will be deleted
306 // again in the handler
307 if( pTargetList )
309 TargetList aTargetList( *pTargetList );
311 for ( size_t i = 0, n = aTargetList.size(); i < n; ++i )
312 pOwnData->aUpdateTargetList.push_back( aTargetList[ i ] );
315 pOwnData->aTimer.Start();
319 void SvxIMapDlg::KeyInput( const KeyEvent& rKEvt )
321 SfxModelessDialog::KeyInput( rKEvt );
324 // Click-handler for ToolBox
326 IMPL_LINK( SvxIMapDlg, TbxClickHdl, ToolBox*, pTbx )
328 sal_uInt16 nNewItemId = pTbx->GetCurItemId();
330 switch( pTbx->GetCurItemId() )
332 case( TBI_APPLY ):
334 URLLoseFocusHdl( NULL );
335 SfxBoolItem aBoolItem( SID_IMAP_EXEC, true );
336 GetBindings().GetDispatcher()->Execute(
337 SID_IMAP_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
339 break;
341 case( TBI_OPEN ):
342 DoOpen();
343 break;
345 case( TBI_SAVEAS ):
346 DoSave();
347 break;
349 case( TBI_SELECT ):
351 pTbx->CheckItem( nNewItemId, true );
352 pIMapWnd->SetEditMode( true );
353 if( pTbx->IsKeyEvent() )
355 if((pTbx->GetKeyModifier() & KEY_MOD1) != 0)
356 pIMapWnd->SelectFirstObject();
357 else
358 pIMapWnd->GrabFocus();
361 break;
363 case( TBI_RECT ):
365 pTbx->CheckItem( nNewItemId, true );
366 pIMapWnd->SetObjKind( OBJ_RECT );
367 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
369 pIMapWnd->CreateDefaultObject();
370 pIMapWnd->GrabFocus();
373 break;
375 case( TBI_CIRCLE ):
377 pTbx->CheckItem( nNewItemId, true );
378 pIMapWnd->SetObjKind( OBJ_CIRC );
379 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
381 pIMapWnd->CreateDefaultObject();
382 pIMapWnd->GrabFocus();
385 break;
387 case( TBI_POLY ):
389 pTbx->CheckItem( nNewItemId, true );
390 pIMapWnd->SetObjKind( OBJ_POLY );
391 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
393 pIMapWnd->CreateDefaultObject();
394 pIMapWnd->GrabFocus();
397 break;
399 case( TBI_FREEPOLY ):
401 pTbx->CheckItem( nNewItemId, true );
402 pIMapWnd->SetObjKind( OBJ_FREEFILL );
403 if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
405 pIMapWnd->CreateDefaultObject();
406 pIMapWnd->GrabFocus();
409 break;
411 case( TBI_ACTIVE ):
413 URLLoseFocusHdl( NULL );
414 bool bNewState = !pTbx->IsItemChecked( TBI_ACTIVE );
415 pTbx->CheckItem( TBI_ACTIVE, bNewState );
416 pIMapWnd->SetCurrentObjState( !bNewState );
418 break;
420 case( TBI_MACRO ):
421 pIMapWnd->DoMacroAssign();
422 break;
424 case( TBI_PROPERTY ):
425 pIMapWnd->DoPropertyDialog();
426 break;
428 case( TBI_POLYEDIT ):
429 pIMapWnd->SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
430 if( pTbx->IsKeyEvent() && pTbx->IsItemChecked( TBI_POLYEDIT ) )
431 pIMapWnd->StartPolyEdit();
432 break;
434 case( TBI_POLYMOVE ):
435 pIMapWnd->SetPolyEditMode( SID_BEZIER_MOVE );
436 break;
438 case( TBI_POLYINSERT ):
439 pIMapWnd->SetPolyEditMode( SID_BEZIER_INSERT );
440 break;
442 case( TBI_POLYDELETE ):
443 pIMapWnd->GetSdrView()->DeleteMarkedPoints();
444 break;
446 case( TBI_UNDO ):
448 URLLoseFocusHdl( NULL );
449 pIMapWnd->GetSdrModel()->Undo();
451 break;
453 case( TBI_REDO ):
455 URLLoseFocusHdl( NULL );
456 pIMapWnd->GetSdrModel()->Redo();
458 break;
460 default:
461 break;
464 return 0;
467 void SvxIMapDlg::DoOpen()
469 ::sfx2::FileDialogHelper aDlg(
470 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
472 ImageMap aLoadIMap;
473 const OUString aFilter( IMAP_ALL_FILTER );
475 aDlg.AddFilter( aFilter, IMAP_ALL_TYPE );
476 aDlg.AddFilter( IMAP_CERN_FILTER, IMAP_CERN_TYPE );
477 aDlg.AddFilter( IMAP_NCSA_FILTER, IMAP_NCSA_TYPE );
478 aDlg.AddFilter( IMAP_BINARY_FILTER, IMAP_BINARY_TYPE );
480 aDlg.SetCurrentFilter( aFilter );
481 aDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
483 if( aDlg.Execute() == ERRCODE_NONE )
485 INetURLObject aURL( aDlg.GetPath() );
486 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
487 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
489 if( pIStm )
491 aLoadIMap.Read( *pIStm, IMAP_FORMAT_DETECT, "" );
493 if( pIStm->GetError() )
495 SfxErrorContext eEC(ERRCODE_SFX_GENERAL,this);
496 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
498 else
499 pIMapWnd->SetImageMap( aLoadIMap );
501 delete pIStm;
504 pIMapWnd->Invalidate();
508 bool SvxIMapDlg::DoSave()
510 ::sfx2::FileDialogHelper aDlg(
511 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
513 const OUString aBinFilter( IMAP_BINARY_FILTER );
514 const OUString aCERNFilter( IMAP_CERN_FILTER );
515 const OUString aNCSAFilter( IMAP_NCSA_FILTER );
516 SdrModel* pModel = pIMapWnd->GetSdrModel();
517 const bool bChanged = pModel->IsChanged();
518 bool bRet = false;
520 aDlg.AddFilter( aCERNFilter, IMAP_CERN_TYPE );
521 aDlg.AddFilter( aNCSAFilter, IMAP_NCSA_TYPE );
522 aDlg.AddFilter( aBinFilter, IMAP_BINARY_TYPE );
524 aDlg.SetCurrentFilter( aCERNFilter );
525 aDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
527 if( aDlg.Execute() == ERRCODE_NONE )
529 const OUString aFilter( aDlg.GetCurrentFilter() );
530 OUString aExt;
531 sal_uIntPtr nFormat;
533 if ( aFilter == aBinFilter )
535 nFormat = IMAP_FORMAT_BIN;
536 aExt = IMAP_BINARY_EXT;
538 else if ( aFilter == aCERNFilter )
540 nFormat = IMAP_FORMAT_CERN;
541 aExt = IMAP_CERN_EXT;
543 else if ( aFilter == aNCSAFilter )
545 nFormat = IMAP_FORMAT_NCSA;
546 aExt = IMAP_NCSA_EXT;
548 else
550 return false;
553 INetURLObject aURL( aDlg.GetPath() );
555 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
557 OSL_FAIL( "invalid URL" );
559 else
561 if( aURL.getExtension().isEmpty() )
562 aURL.setExtension( aExt );
564 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
565 if( pOStm )
567 pIMapWnd->GetImageMap().Write( *pOStm, nFormat, "" );
569 if( pOStm->GetError() )
570 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
572 delete pOStm;
573 pModel->SetChanged( bChanged );
574 bRet = true;
579 return bRet;
582 IMPL_LINK( SvxIMapDlg, InfoHdl, IMapWindow*, pWnd )
584 OUString aStr;
585 const NotifyInfo& rInfo = pWnd->GetInfo();
587 if ( rInfo.bNewObj )
589 if( !rInfo.aMarkURL.isEmpty() && ( maURLBox.GetEntryPos( rInfo.aMarkURL ) == LISTBOX_ENTRY_NOTFOUND ) )
590 maURLBox.InsertEntry( rInfo.aMarkURL );
592 maURLBox.SetText( rInfo.aMarkURL );
593 aEdtText.SetText( rInfo.aMarkAltText );
595 if ( rInfo.aMarkTarget.isEmpty() )
596 maCbbTarget.SetText( SELF_TARGET );
597 else
598 maCbbTarget.SetText( rInfo.aMarkTarget );
601 if ( !rInfo.bOneMarked )
603 aTbxIMapDlg1.CheckItem( TBI_ACTIVE, false );
604 aTbxIMapDlg1.EnableItem( TBI_ACTIVE, false );
605 aTbxIMapDlg1.EnableItem( TBI_MACRO, false );
606 aTbxIMapDlg1.EnableItem( TBI_PROPERTY, false );
607 aStbStatus.SetItemText( 1, aStr );
609 aFtURL.Disable();
610 maURLBox.Disable();
611 aFtText.Disable();
612 aEdtText.Disable();
613 maFtTarget.Disable();
614 maCbbTarget.Disable();
616 maURLBox.SetText( "" );
617 aEdtText.SetText( "" );
619 else
621 aTbxIMapDlg1.EnableItem( TBI_ACTIVE, true );
622 aTbxIMapDlg1.CheckItem( TBI_ACTIVE, !rInfo.bActivated );
623 aTbxIMapDlg1.EnableItem( TBI_MACRO, true );
624 aTbxIMapDlg1.EnableItem( TBI_PROPERTY, true );
626 aFtURL.Enable();
627 maURLBox.Enable();
628 aFtText.Enable();
629 aEdtText.Enable();
630 maFtTarget.Enable();
631 maCbbTarget.Enable();
633 aStbStatus.SetItemText( 1, rInfo.aMarkURL );
635 if ( maURLBox.GetText() != OUString(rInfo.aMarkURL) )
636 maURLBox.SetText( rInfo.aMarkURL );
638 if ( aEdtText.GetText() != OUString(rInfo.aMarkAltText) )
639 aEdtText.SetText( rInfo.aMarkAltText );
641 if ( rInfo.aMarkTarget.isEmpty() )
642 maCbbTarget.SetText( SELF_TARGET );
643 else
644 maCbbTarget.SetText( rInfo.aMarkTarget );
647 return 0;
650 IMPL_LINK( SvxIMapDlg, MousePosHdl, IMapWindow*, pWnd )
652 const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
653 const Point& rMousePos = pWnd->GetMousePos();
654 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
655 const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
657 OUString aStr = GetUnitString( rMousePos.X(), eFieldUnit, cSep ) +
658 " / " + GetUnitString( rMousePos.Y(), eFieldUnit, cSep );
660 aStbStatus.SetItemText( 2, aStr );
662 return 0L;
665 IMPL_LINK( SvxIMapDlg, GraphSizeHdl, IMapWindow*, pWnd )
667 const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
668 const Size& rSize = pWnd->GetGraphicSize();
669 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
670 const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
672 OUString aStr = GetUnitString( rSize.Width(), eFieldUnit, cSep ) +
673 " x " + GetUnitString( rSize.Height(), eFieldUnit, cSep );
675 aStbStatus.SetItemText( 3, aStr );
677 return 0L;
680 IMPL_LINK_NOARG(SvxIMapDlg, URLModifyHdl)
682 NotifyInfo aNewInfo;
684 aNewInfo.aMarkURL = maURLBox.GetText();
685 aNewInfo.aMarkAltText = aEdtText.GetText();
686 aNewInfo.aMarkTarget = maCbbTarget.GetText();
688 pIMapWnd->ReplaceActualIMapInfo( aNewInfo );
690 return 0;
693 IMPL_LINK_NOARG(SvxIMapDlg, URLLoseFocusHdl)
695 NotifyInfo aNewInfo;
696 const OUString aURLText( maURLBox.GetText() );
697 const OUString aTargetText( maCbbTarget.GetText() );
699 if ( !aURLText.isEmpty() )
701 OUString aBase = GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
702 aNewInfo.aMarkURL = ::URIHelper::SmartRel2Abs( INetURLObject(aBase), aURLText, URIHelper::GetMaybeFileHdl(), true, false,
703 INetURLObject::WAS_ENCODED,
704 INetURLObject::DECODE_UNAMBIGUOUS );
706 else
707 aNewInfo.aMarkURL = aURLText;
709 aNewInfo.aMarkAltText = aEdtText.GetText();
711 if ( aTargetText.isEmpty() )
712 aNewInfo.aMarkTarget = SELF_TARGET;
713 else
714 aNewInfo.aMarkTarget = aTargetText;
716 pIMapWnd->ReplaceActualIMapInfo( aNewInfo );
718 return 0;
721 IMPL_LINK_NOARG(SvxIMapDlg, UpdateHdl)
723 pOwnData->aTimer.Stop();
725 if ( pOwnData->pUpdateEditingObject != pCheckObj )
727 if ( pIMapWnd->IsChanged() &&
728 ( MessageDialog( this,"QuerySaveImageMapChangesDialog",
729 "svx/ui/querysaveimagemapchangesdialog.ui" ).Execute() == RET_YES ) )
731 DoSave();
734 SetGraphic( pOwnData->aUpdateGraphic );
735 SetImageMap( pOwnData->aUpdateImageMap );
736 SetTargetList( pOwnData->aUpdateTargetList );
737 SetEditingObject( pOwnData->pUpdateEditingObject );
739 // After changes => default selection
740 aTbxIMapDlg1.CheckItem( TBI_SELECT, true );
741 pIMapWnd->SetEditMode( true );
744 // Delete the copied list again in the Update method
745 pOwnData->aUpdateTargetList.clear();
747 GetBindings().Invalidate( SID_IMAP_EXEC );
749 return 0L;
752 IMPL_LINK( SvxIMapDlg, StateHdl, IMapWindow*, pWnd )
754 const SdrObject* pObj = pWnd->GetSelectedSdrObject();
755 const SdrModel* pModel = pWnd->GetSdrModel();
756 const SdrView* pView = pWnd->GetSdrView();
757 const bool bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
758 const bool bDrawEnabled = !( bPolyEdit && aTbxIMapDlg1.IsItemChecked( TBI_POLYEDIT ) );
760 aTbxIMapDlg1.EnableItem( TBI_APPLY, pOwnData->bExecState && pWnd->IsChanged() );
762 aTbxIMapDlg1.EnableItem( TBI_SELECT, bDrawEnabled );
763 aTbxIMapDlg1.EnableItem( TBI_RECT, bDrawEnabled );
764 aTbxIMapDlg1.EnableItem( TBI_CIRCLE, bDrawEnabled );
765 aTbxIMapDlg1.EnableItem( TBI_POLY, bDrawEnabled );
766 aTbxIMapDlg1.EnableItem( TBI_FREEPOLY, bDrawEnabled );
768 // BezierEditor State
769 aTbxIMapDlg1.EnableItem( TBI_POLYEDIT, bPolyEdit );
770 aTbxIMapDlg1.EnableItem( TBI_POLYMOVE, !bDrawEnabled );
771 aTbxIMapDlg1.EnableItem( TBI_POLYINSERT, !bDrawEnabled );
772 aTbxIMapDlg1.EnableItem( TBI_POLYDELETE, !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
774 // Undo/Redo
775 aTbxIMapDlg1.EnableItem( TBI_UNDO, pModel->HasUndoActions() );
776 aTbxIMapDlg1.EnableItem( TBI_REDO, pModel->HasRedoActions() );
778 if ( bPolyEdit )
780 sal_uInt16 nId = 0;
782 switch( pWnd->GetPolyEditMode() )
784 case( SID_BEZIER_MOVE ): nId = TBI_POLYMOVE; break;
785 case( SID_BEZIER_INSERT ): nId = TBI_POLYINSERT; break;
787 default:
788 break;
791 aTbxIMapDlg1.CheckItem( nId, true );
793 else
795 aTbxIMapDlg1.CheckItem( TBI_POLYEDIT, false );
796 aTbxIMapDlg1.CheckItem( TBI_POLYMOVE, true );
797 aTbxIMapDlg1.CheckItem( TBI_POLYINSERT, false );
798 pWnd->SetPolyEditMode( 0 );
801 return 0L;
804 IMPL_LINK_NOARG(SvxIMapDlg, MiscHdl)
806 SvtMiscOptions aMiscOptions;
807 aTbxIMapDlg1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
809 return 0L;
812 void SvxIMapDlg::ApplyImageList()
814 ImageList& rImgLst = maImageList;
816 aTbxIMapDlg1.SetImageList( rImgLst );
819 void SvxIMapDlg::DataChanged( const DataChangedEvent& rDCEvt )
821 SfxModelessDialog::DataChanged( rDCEvt );
823 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
824 ApplyImageList();
827 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */