xref: /AOO41X/main/svx/source/dialog/imapdlg.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #define _SDR_NOITEMS
28 #define _SDR_NOTOUCH
29 #define _SDR_NOTRANSFORM
30 #define _SDR_NOOBJECTS
31 #define _SDR_NOVIEWMARKER
32 #define _SDR_NODRAGMETHODS
33 #define _SDR_NOUNDO
34 #define _SDR_NOXOUTDEV
35 
36 #include <stdlib.h>
37 #include <tools/shl.hxx>
38 #ifndef _EINF_HXX
39 #include <tools/errinf.hxx>
40 #endif
41 #include <tools/urlobj.hxx>
42 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
43 #include <unotools/ucbstreamhelper.hxx>
44 #endif
45 #include <vcl/msgbox.hxx>
46 #include <vcl/group.hxx>
47 #include <vcl/lstbox.hxx>
48 #include <svl/eitem.hxx>
49 #include <unotools/pathoptions.hxx>
50 #include <sfx2/dispatch.hxx>
51 #include <sfx2/module.hxx>
52 #include <sfx2/filedlghelper.hxx>
53 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
54 #include <svl/urihelper.hxx>
55 #include <svtools/miscopt.hxx>
56 #include <svtools/ehdl.hxx>
57 #include <svtools/sfxecode.hxx>
58 #include <sfx2/viewfrm.hxx>
59 #include <sfx2/objsh.hxx>
60 #include <sfx2/docfile.hxx>
61 #include <unotools/localedatawrapper.hxx>
62 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
63 #include <comphelper/processfactory.hxx>
64 #endif
65 
66 #define _IMAPDLG_PRIVATE
67 #include "svx/imapdlg.hxx"
68 
69 #include <svx/dialmgr.hxx>
70 #include <svx/dialogs.hrc>
71 #include <svx/svxids.hrc>
72 #include "imapdlg.hrc"
73 #include "imapwnd.hxx"
74 #include "imapimp.hxx"
75 #include "svx/dlgutil.hxx"
76 #include <svx/svdtrans.hxx>
77 #include <svx/svdopath.hxx>
78 #include <vcl/svapp.hxx>
79 
80 #define SELF_TARGET         "_self"
81 #define IMAP_ALL_FILTER     "<Alle>"
82 #define IMAP_CERN_FILTER    "MAP - CERN"
83 #define IMAP_NCSA_FILTER    "MAP - NCSA"
84 #define IMAP_BINARY_FILTER  "SIP - StarView ImageMap"
85 #define IMAP_ALL_TYPE       "*.*"
86 #define IMAP_BINARY_TYPE    "*.sip"
87 #define IMAP_CERN_TYPE      "*.map"
88 #define IMAP_NCSA_TYPE      "*.map"
89 #define IMAP_BINARY_EXT     "sip"
90 #define IMAP_CERN_EXT       "map"
91 #define IMAP_NCSA_EXT       "map"
92 
93 /******************************************************************************/
94 
95 SFX_IMPL_MODELESSDIALOG( SvxIMapDlgChildWindow, SID_IMAP );
96 
97 /******************************************************************************/
98 
GetUnitString(long nVal_100,FieldUnit eFieldUnit,sal_Unicode cSep)99 inline String GetUnitString( long nVal_100, FieldUnit eFieldUnit, sal_Unicode cSep )
100 {
101     String aVal = UniString::CreateFromInt64( MetricField::ConvertValue( nVal_100, 2, MAP_100TH_MM, eFieldUnit ) );
102 
103     while( aVal.Len() < 3 )
104         aVal.Insert( sal_Unicode('0'), 0 );
105 
106     aVal.Insert( cSep, aVal.Len() - 2 );
107     aVal += sal_Unicode(' ');
108     aVal += SdrFormatter::GetUnitStr( eFieldUnit );
109 
110     return aVal;
111 }
112 
113 /*************************************************************************
114 |*
115 |* ControllerItem
116 |*
117 \************************************************************************/
118 
SvxIMapDlgItem(sal_uInt16 _nId,SvxIMapDlg & rIMapDlg,SfxBindings & rBindings)119 SvxIMapDlgItem::SvxIMapDlgItem( sal_uInt16 _nId, SvxIMapDlg& rIMapDlg, SfxBindings& rBindings ) :
120             SfxControllerItem   ( _nId, rBindings ),
121             rIMap               ( rIMapDlg )
122 {
123 }
124 
125 /*************************************************************************
126 |*
127 |* StateChanged-Methode
128 |*
129 \************************************************************************/
130 
StateChanged(sal_uInt16 nSID,SfxItemState,const SfxPoolItem * pItem)131 void SvxIMapDlgItem::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/,
132                                    const SfxPoolItem* pItem )
133 {
134     if ( ( nSID == SID_IMAP_EXEC ) && pItem )
135     {
136         const SfxBoolItem* pStateItem = PTR_CAST( SfxBoolItem, pItem );
137 
138         DBG_ASSERT( pStateItem || pItem == 0, "SfxBoolItem erwartet");
139 
140         // Float ggf. disablen
141         rIMap.SetExecState( !pStateItem->GetValue() );
142     }
143 }
144 
145 /*************************************************************************
146 |*
147 |*
148 |*
149 \************************************************************************/
150 
SvxIMapDlgChildWindow(Window * _pParent,sal_uInt16 nId,SfxBindings * pBindings,SfxChildWinInfo * pInfo)151 SvxIMapDlgChildWindow::SvxIMapDlgChildWindow( Window* _pParent, sal_uInt16 nId,
152                                               SfxBindings* pBindings,
153                                               SfxChildWinInfo* pInfo ) :
154             SfxChildWindow( _pParent, nId )
155 {
156     pWindow = new SvxIMapDlg( pBindings, this, _pParent, SVX_RES( RID_SVXDLG_IMAP ) );
157     SvxIMapDlg* pDlg = (SvxIMapDlg*) pWindow;
158 
159     if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
160         pDlg->RollUp();
161 
162     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
163 
164     pDlg->Initialize( pInfo );
165 }
166 
167 
168 /*************************************************************************
169 |*
170 |*
171 |*
172 \************************************************************************/
173 
UpdateIMapDlg(const Graphic & rGraphic,const ImageMap * pImageMap,const TargetList * pTargetList,void * pEditingObj)174 void SvxIMapDlgChildWindow::UpdateIMapDlg( const Graphic& rGraphic, const ImageMap* pImageMap,
175                                            const TargetList* pTargetList, void* pEditingObj )
176 {
177     if ( SfxViewFrame::Current() &&
178          SfxViewFrame::Current()->HasChildWindow( SvxIMapDlgChildWindow::GetChildWindowId() ) )
179         SVXIMAPDLG()->Update( rGraphic, pImageMap, pTargetList, pEditingObj );
180 }
181 
182 
183 /*************************************************************************
184 |*
185 |*
186 |*
187 \************************************************************************/
188 
SvxIMapDlg(SfxBindings * _pBindings,SfxChildWindow * pCW,Window * _pParent,const ResId & rResId)189 SvxIMapDlg::SvxIMapDlg( SfxBindings *_pBindings, SfxChildWindow *pCW,
190                         Window* _pParent, const ResId& rResId ) :
191         SfxModelessDialog   ( _pBindings, pCW, _pParent, rResId ),
192 
193         aTbxIMapDlg1        ( this, SVX_RES( TBX_IMAPDLG1 ) ),
194         aFtURL              ( this, SVX_RES( FT_URL ) ),
195         maURLBox            ( this, SVX_RES( CBB_URL ) ),
196         aFtText             ( this, SVX_RES( FT_TEXT ) ),
197         aEdtText            ( this, SVX_RES( EDT_TEXT ) ),
198         maFtTarget          ( this, SVX_RES( RID_SVXCTL_FT_TARGET ) ),
199         maCbbTarget         ( this, SVX_RES( RID_SVXCTL_CBB_TARGET ) ),
200         aStbStatus          ( this, WB_BORDER | WB_3DLOOK | WB_LEFT ),
201         maImageList         ( SVX_RES( IL_IMAPDLG ) ),
202         maImageListH        ( SVX_RES( ILH_IMAPDLG ) ),
203         pCheckObj           ( NULL ),
204         aIMapItem           ( SID_IMAP_EXEC, *this, *_pBindings )
205 {
206     pIMapWnd = new IMapWindow( this, SVX_RES( RID_SVXCTL_IMAP ), _pBindings->GetActiveFrame() );
207 
208     ApplyImageList();
209 
210     FreeResource();
211 
212     pOwnData = new IMapOwnData( this );
213 
214     pIMapWnd->SetInfoLink( LINK( this, SvxIMapDlg, InfoHdl ) );
215     pIMapWnd->SetMousePosLink( LINK( this, SvxIMapDlg, MousePosHdl ) );
216     pIMapWnd->SetGraphSizeLink( LINK( this, SvxIMapDlg, GraphSizeHdl ) );
217     pIMapWnd->SetUpdateLink( LINK( this, SvxIMapDlg, StateHdl ) );
218 
219     maURLBox.SetModifyHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
220     maURLBox.SetSelectHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
221     maURLBox.SetLoseFocusHdl( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
222     aEdtText.SetModifyHdl( LINK( this, SvxIMapDlg, URLModifyHdl ) );
223     maCbbTarget.SetLoseFocusHdl( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
224 
225     SvtMiscOptions aMiscOptions;
226     aMiscOptions.AddListenerLink( LINK( this, SvxIMapDlg, MiscHdl ) );
227 
228     aTbxIMapDlg1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
229     aTbxIMapDlg1.SetSizePixel( aTbxIMapDlg1.CalcWindowSizePixel() );
230     aTbxIMapDlg1.SetSelectHdl( LINK( this, SvxIMapDlg, TbxClickHdl ) );
231     aTbxIMapDlg1.CheckItem( TBI_SELECT, sal_True );
232     TbxClickHdl( &aTbxIMapDlg1 );
233 
234     SetMinOutputSizePixel( aLastSize = GetOutputSizePixel() );
235 
236     aStbStatus.InsertItem( 1, 130, SIB_LEFT | SIB_IN | SIB_AUTOSIZE );
237     aStbStatus.InsertItem( 2, 10 + GetTextWidth( DEFINE_CONST_UNICODE( " 9999,99 cm / 9999,99 cm ") ), SIB_CENTER | SIB_IN );
238     aStbStatus.InsertItem( 3, 10 + GetTextWidth( DEFINE_CONST_UNICODE( " 9999,99 cm x 9999,99 cm ") ), SIB_CENTER | SIB_IN );
239 
240     aFtURL.Disable();
241     maURLBox.Disable();
242     aFtText.Disable();
243     aEdtText.Disable();
244     maFtTarget.Disable();
245     maCbbTarget.Disable();
246     pOwnData->bExecState = sal_False;
247 
248     Resize();
249 
250     pOwnData->aTimer.SetTimeout( 100 );
251     pOwnData->aTimer.SetTimeoutHdl( LINK( this, SvxIMapDlg, UpdateHdl ) );
252 
253     aTbxIMapDlg1.EnableItem( TBI_ACTIVE, sal_False );
254     aTbxIMapDlg1.EnableItem( TBI_MACRO, sal_False );
255     aTbxIMapDlg1.EnableItem( TBI_PROPERTY, sal_False );
256 }
257 
258 
259 /*************************************************************************
260 |*
261 |* Dtor
262 |*
263 \************************************************************************/
264 
~SvxIMapDlg()265 SvxIMapDlg::~SvxIMapDlg()
266 {
267     // URL-Liste loeschen
268     delete pIMapWnd;
269     delete pOwnData;
270 }
271 
272 
273 /*************************************************************************
274 |*
275 |* Resize-Methode
276 |*
277 \************************************************************************/
278 
Resize()279 void SvxIMapDlg::Resize()
280 {
281     SfxModelessDialog::Resize();
282 
283     Size aMinSize( GetMinOutputSizePixel() );
284     Size aNewSize( GetOutputSizePixel() );
285 
286     if ( aNewSize.Height() >= aMinSize.Height() )
287     {
288         Size    _aSize( aStbStatus.GetSizePixel() );
289         Point   aPoint( 0, aNewSize.Height() - _aSize.Height() );
290 
291         // StatusBar positionieren
292         aStbStatus.SetPosSizePixel( aPoint, Size( aNewSize.Width(), _aSize.Height() ) );
293         aStbStatus.Show();
294 
295         // EditWindow positionieren
296         _aSize.Width() = aNewSize.Width() - 18;
297         _aSize.Height() = aPoint.Y() - pIMapWnd->GetPosPixel().Y() - 6;
298         pIMapWnd->SetSizePixel( _aSize );
299 
300         aLastSize = aNewSize;
301     }
302 }
303 
304 
305 /*************************************************************************
306 |*
307 |* Close-Methode
308 |*
309 \************************************************************************/
310 
Close()311 sal_Bool SvxIMapDlg::Close()
312 {
313     sal_Bool bRet = sal_True;
314 
315     if ( aTbxIMapDlg1.IsItemEnabled( TBI_APPLY ) )
316     {
317         QueryBox    aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
318                            String( SVX_RES( STR_IMAPDLG_MODIFY ) ) );
319         const long  nRet = aQBox.Execute();
320 
321         if( nRet == RET_YES )
322         {
323             SfxBoolItem aBoolItem( SID_IMAP_EXEC, sal_True );
324             GetBindings().GetDispatcher()->Execute(
325                 SID_IMAP_EXEC, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
326         }
327         else if( nRet == RET_CANCEL )
328             bRet = sal_False;
329     }
330     else if( pIMapWnd->IsChanged() )
331     {
332         QueryBox    aQBox( this, WB_YES_NO_CANCEL | WB_DEF_YES,
333                            String( SVX_RES( STR_IMAPDLG_SAVE ) ) );
334         const long  nRet = aQBox.Execute();
335 
336         if( nRet == RET_YES )
337             bRet = DoSave();
338         else if( nRet == RET_CANCEL )
339             bRet = sal_False;
340     }
341 
342     return( bRet ? SfxModelessDialog::Close() : sal_False );
343 }
344 
345 
346 /*************************************************************************
347 |*
348 |* Enabled oder disabled alle Controls
349 |*
350 \************************************************************************/
351 
SetExecState(sal_Bool bEnable)352 void SvxIMapDlg::SetExecState( sal_Bool bEnable )
353 {
354     pOwnData->bExecState = bEnable;
355 }
356 
357 
358 /*************************************************************************
359 |*
360 |*
361 |*
362 \************************************************************************/
363 
SetGraphic(const Graphic & rGraphic)364 void SvxIMapDlg::SetGraphic( const Graphic& rGraphic )
365 {
366     pIMapWnd->SetGraphic( rGraphic );
367 }
368 
369 
370 /*************************************************************************
371 |*
372 |*
373 |*
374 \************************************************************************/
375 
SetImageMap(const ImageMap & rImageMap)376 void SvxIMapDlg::SetImageMap( const ImageMap& rImageMap )
377 {
378     pIMapWnd->SetImageMap( rImageMap );
379 }
380 
381 
382 /*************************************************************************
383 |*
384 |*
385 |*
386 \************************************************************************/
387 
GetImageMap() const388 const ImageMap& SvxIMapDlg::GetImageMap() const
389 {
390     return pIMapWnd->GetImageMap();
391 }
392 
393 
394 /*************************************************************************
395 |*
396 |*
397 |*
398 \************************************************************************/
399 
SetTargetList(const TargetList & rTargetList)400 void SvxIMapDlg::SetTargetList( const TargetList& rTargetList )
401 {
402     TargetList  aNewList( rTargetList );
403 
404     pIMapWnd->SetTargetList( aNewList );
405 
406     maCbbTarget.Clear();
407 
408     for( String* pStr = aNewList.First(); pStr; pStr = aNewList.Next() )
409         maCbbTarget.InsertEntry( *pStr );
410 }
411 
412 
413 /*************************************************************************
414 |*
415 |*
416 |*
417 \************************************************************************/
418 
GetTargetList() const419 const TargetList& SvxIMapDlg::GetTargetList() const
420 {
421     return pIMapWnd->GetTargetList();
422 }
423 
424 
425 /*************************************************************************
426 |*
427 |*
428 |*
429 \************************************************************************/
430 
Update(const Graphic & rGraphic,const ImageMap * pImageMap,const TargetList * pTargetList,void * pEditingObj)431 void SvxIMapDlg::Update( const Graphic& rGraphic, const ImageMap* pImageMap,
432                          const TargetList* pTargetList, void* pEditingObj )
433 {
434     pOwnData->aUpdateGraphic = rGraphic;
435 
436     if ( pImageMap )
437         pOwnData->aUpdateImageMap = *pImageMap;
438     else
439         pOwnData->aUpdateImageMap.ClearImageMap();
440 
441     pOwnData->pUpdateEditingObject = pEditingObj;
442 
443     // UpdateTargetList loeschen, da diese Methode
444     // vor dem Zuschlagen des Update-Timers noch
445     // mehrmals gerufen werden kann( #46540 )
446     for( String* pStr = pOwnData->aUpdateTargetList.First(); pStr; pStr = pOwnData->aUpdateTargetList.Next() )
447         delete pStr;
448     pOwnData->aUpdateTargetList.Clear();
449 
450     // TargetListe muss kopiert werden, da sie im
451     // Besitz des Aufrufers ist und von ihm nach diesem
452     // Aufruf sofort geloescht werden kann;
453     // die kopierte Liste wird im Handler wieder geloescht
454     if( pTargetList )
455     {
456         TargetList aTargetList( *pTargetList );
457 
458         for( String* pStr = aTargetList.First(); pStr; pStr = aTargetList.Next() )
459             pOwnData->aUpdateTargetList.Insert( new String( *pStr ) );
460     }
461 
462     pOwnData->aTimer.Start();
463 }
464 
465 
KeyInput(const KeyEvent & rKEvt)466 void SvxIMapDlg::KeyInput( const KeyEvent& rKEvt )
467 {
468         SfxModelessDialog::KeyInput( rKEvt );
469 }
470 
471 /*************************************************************************
472 |*
473 |* Click-Hdl fuer ToolBox
474 |*
475 \************************************************************************/
476 
IMPL_LINK(SvxIMapDlg,TbxClickHdl,ToolBox *,pTbx)477 IMPL_LINK( SvxIMapDlg, TbxClickHdl, ToolBox*, pTbx )
478 {
479     sal_uInt16 nNewItemId = pTbx->GetCurItemId();
480 
481     switch( pTbx->GetCurItemId() )
482     {
483         case( TBI_APPLY ):
484         {
485             URLLoseFocusHdl( NULL );
486             SfxBoolItem aBoolItem( SID_IMAP_EXEC, sal_True );
487             GetBindings().GetDispatcher()->Execute(
488                 SID_IMAP_EXEC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aBoolItem, 0L );
489         }
490         break;
491 
492         case( TBI_OPEN ):
493             DoOpen();
494         break;
495 
496         case( TBI_SAVEAS ):
497             DoSave();
498         break;
499 
500         case( TBI_SELECT ):
501         {
502             pTbx->CheckItem( nNewItemId, sal_True );
503             pIMapWnd->SetEditMode( sal_True );
504             if( pTbx->IsKeyEvent() )
505             {
506                 if((pTbx->GetKeyModifier() & KEY_MOD1) != 0)
507                     pIMapWnd->SelectFirstObject();
508                 else
509                     pIMapWnd->GrabFocus();
510             }
511         }
512         break;
513 
514         case( TBI_RECT ):
515         {
516             pTbx->CheckItem( nNewItemId, sal_True );
517             pIMapWnd->SetObjKind( OBJ_RECT );
518             if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
519             {
520                 pIMapWnd->CreateDefaultObject();
521                 pIMapWnd->GrabFocus();
522             }
523         }
524         break;
525 
526         case( TBI_CIRCLE ):
527         {
528             pTbx->CheckItem( nNewItemId, sal_True );
529             pIMapWnd->SetObjKind( OBJ_CIRC );
530             if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
531             {
532                 pIMapWnd->CreateDefaultObject();
533                 pIMapWnd->GrabFocus();
534             }
535         }
536         break;
537 
538         case( TBI_POLY ):
539         {
540             pTbx->CheckItem( nNewItemId, sal_True );
541             pIMapWnd->SetObjKind( OBJ_POLY );
542             if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
543             {
544                 pIMapWnd->CreateDefaultObject();
545                 pIMapWnd->GrabFocus();
546             }
547         }
548         break;
549 
550         case( TBI_FREEPOLY ):
551         {
552             pTbx->CheckItem( nNewItemId, sal_True );
553             pIMapWnd->SetObjKind( OBJ_FREEFILL );
554             if( pTbx->IsKeyEvent() && ((pTbx->GetKeyModifier() & KEY_MOD1) != 0) )
555             {
556                 pIMapWnd->CreateDefaultObject();
557                 pIMapWnd->GrabFocus();
558             }
559         }
560         break;
561 
562         case( TBI_ACTIVE ):
563         {
564             URLLoseFocusHdl( NULL );
565             sal_Bool bNewState = !pTbx->IsItemChecked( TBI_ACTIVE );
566             pTbx->CheckItem( TBI_ACTIVE, bNewState );
567             pIMapWnd->SetCurrentObjState( !bNewState );
568         }
569         break;
570 
571         case( TBI_MACRO ):
572             pIMapWnd->DoMacroAssign();
573         break;
574 
575         case( TBI_PROPERTY ):
576             pIMapWnd->DoPropertyDialog();
577         break;
578 
579         case( TBI_POLYEDIT ):
580             pIMapWnd->SetPolyEditMode( pTbx->IsItemChecked( TBI_POLYEDIT ) ? SID_BEZIER_MOVE : 0 );
581             if( pTbx->IsKeyEvent() && pTbx->IsItemChecked( TBI_POLYEDIT ) )
582                 pIMapWnd->StartPolyEdit();
583         break;
584 
585         case( TBI_POLYMOVE ):
586             pIMapWnd->SetPolyEditMode( SID_BEZIER_MOVE );
587         break;
588 
589         case( TBI_POLYINSERT ):
590             pIMapWnd->SetPolyEditMode( SID_BEZIER_INSERT );
591         break;
592 
593         case( TBI_POLYDELETE ):
594             pIMapWnd->GetSdrView()->DeleteMarkedPoints();
595         break;
596 
597         case( TBI_UNDO ):
598         {
599             URLLoseFocusHdl( NULL );
600             pIMapWnd->GetSdrModel()->Undo();
601         }
602         break;
603 
604         case( TBI_REDO ):
605         {
606             URLLoseFocusHdl( NULL );
607             pIMapWnd->GetSdrModel()->Redo();
608         }
609         break;
610 
611         default:
612         break;
613     }
614 
615     return 0;
616 }
617 
618 
619 /*************************************************************************
620 |*
621 |*
622 |*
623 \************************************************************************/
624 
DoOpen()625 void SvxIMapDlg::DoOpen()
626 {
627     ::sfx2::FileDialogHelper aDlg(
628         com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
629 
630     ImageMap        aLoadIMap;
631     const String    aFilter( DEFINE_CONST_UNICODE( IMAP_ALL_FILTER ) );
632 
633     aDlg.AddFilter( aFilter, DEFINE_CONST_UNICODE( IMAP_ALL_TYPE ) );
634     aDlg.AddFilter( DEFINE_CONST_UNICODE( IMAP_CERN_FILTER ), DEFINE_CONST_UNICODE( IMAP_CERN_TYPE ) );
635     aDlg.AddFilter( DEFINE_CONST_UNICODE( IMAP_NCSA_FILTER ), DEFINE_CONST_UNICODE( IMAP_NCSA_TYPE ) );
636     aDlg.AddFilter( DEFINE_CONST_UNICODE( IMAP_BINARY_FILTER ), DEFINE_CONST_UNICODE( IMAP_BINARY_TYPE ) );
637 
638     aDlg.SetCurrentFilter( aFilter );
639     aDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
640 
641     if( aDlg.Execute() == ERRCODE_NONE )
642     {
643         INetURLObject aURL( aDlg.GetPath() );
644         DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
645         SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
646 
647         if( pIStm )
648         {
649             aLoadIMap.Read( *pIStm, IMAP_FORMAT_DETECT, String() );
650 
651             if( pIStm->GetError() )
652             {
653                 SfxErrorContext eEC(ERRCODE_SFX_GENERAL,this);
654                 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
655             }
656             else
657                 pIMapWnd->SetImageMap( aLoadIMap );
658 
659             delete pIStm;
660         }
661 
662         pIMapWnd->Invalidate();
663     }
664 }
665 
666 
667 /*************************************************************************
668 |*
669 |*
670 |*
671 \************************************************************************/
672 
DoSave()673 sal_Bool SvxIMapDlg::DoSave()
674 {
675     ::sfx2::FileDialogHelper aDlg(
676         com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
677 
678     const String    aBinFilter( DEFINE_CONST_UNICODE( IMAP_BINARY_FILTER ) );
679     const String    aCERNFilter( DEFINE_CONST_UNICODE( IMAP_CERN_FILTER ) );
680     const String    aNCSAFilter( DEFINE_CONST_UNICODE( IMAP_NCSA_FILTER ) );
681     SdrModel*       pModel = pIMapWnd->GetSdrModel();
682     const sal_Bool bChanged = pModel->IsChanged();
683     sal_Bool            bRet = false;
684 
685     aDlg.AddFilter( aCERNFilter, DEFINE_CONST_UNICODE( IMAP_CERN_TYPE ) );
686     aDlg.AddFilter( aNCSAFilter, DEFINE_CONST_UNICODE( IMAP_NCSA_TYPE ) );
687     aDlg.AddFilter( aBinFilter, DEFINE_CONST_UNICODE( IMAP_BINARY_TYPE ) );
688 
689     aDlg.SetCurrentFilter( aCERNFilter );
690     aDlg.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
691 
692     if( aDlg.Execute() == ERRCODE_NONE )
693     {
694         const String    aFilter( aDlg.GetCurrentFilter() );
695         String          aExt;
696         sal_uIntPtr         nFormat;
697 
698         if ( aFilter == aBinFilter )
699         {
700             nFormat = IMAP_FORMAT_BIN;
701             aExt = DEFINE_CONST_UNICODE( IMAP_BINARY_EXT );
702         }
703         else if ( aFilter == aCERNFilter )
704         {
705             nFormat = IMAP_FORMAT_CERN;
706             aExt = DEFINE_CONST_UNICODE( IMAP_CERN_EXT );
707         }
708         else if ( aFilter == aNCSAFilter )
709         {
710             nFormat = IMAP_FORMAT_NCSA;
711             aExt = DEFINE_CONST_UNICODE( IMAP_NCSA_EXT );
712         }
713         else
714         {
715             return sal_False;
716         }
717 
718         INetURLObject aURL( aDlg.GetPath() );
719 
720         if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
721         {
722             DBG_ERROR( "invalid URL" );
723         }
724         else
725         {
726             if( !aURL.getExtension().getLength() )
727                 aURL.setExtension( aExt );
728 
729             SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
730             if( pOStm )
731             {
732                 pIMapWnd->GetImageMap().Write( *pOStm, nFormat, String() );
733 
734                 if( pOStm->GetError() )
735                     ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
736 
737                 delete pOStm;
738                 pModel->SetChanged( bChanged );
739                 bRet = sal_True;
740             }
741         }
742     }
743 
744     return bRet;
745 }
746 
747 
748 /*************************************************************************
749 |*
750 |*
751 |*
752 \************************************************************************/
753 
IMPL_LINK(SvxIMapDlg,InfoHdl,IMapWindow *,pWnd)754 IMPL_LINK( SvxIMapDlg, InfoHdl, IMapWindow*, pWnd )
755 {
756     String              aStr;
757     const NotifyInfo&   rInfo = pWnd->GetInfo();
758 
759     if ( rInfo.bNewObj )
760     {
761         if( rInfo.aMarkURL.Len() && ( maURLBox.GetEntryPos( rInfo.aMarkURL ) == LISTBOX_ENTRY_NOTFOUND ) )
762             maURLBox.InsertEntry( rInfo.aMarkURL );
763 
764         maURLBox.SetText( rInfo.aMarkURL );
765         aEdtText.SetText( rInfo.aMarkAltText );
766 
767         if ( !rInfo.aMarkTarget.Len() )
768             maCbbTarget.SetText( DEFINE_CONST_UNICODE( SELF_TARGET ) );
769         else
770             maCbbTarget.SetText( rInfo.aMarkTarget );
771     }
772 
773     if ( !rInfo.bOneMarked )
774     {
775         aTbxIMapDlg1.CheckItem( TBI_ACTIVE, sal_False );
776         aTbxIMapDlg1.EnableItem( TBI_ACTIVE, sal_False );
777         aTbxIMapDlg1.EnableItem( TBI_MACRO, sal_False );
778         aTbxIMapDlg1.EnableItem( TBI_PROPERTY, sal_False );
779         aStbStatus.SetItemText( 1, aStr );
780 
781         aFtURL.Disable();
782         maURLBox.Disable();
783         aFtText.Disable();
784         aEdtText.Disable();
785         maFtTarget.Disable();
786         maCbbTarget.Disable();
787 
788         maURLBox.SetText( String() );
789         aEdtText.SetText( String() );
790     }
791     else
792     {
793         aTbxIMapDlg1.EnableItem( TBI_ACTIVE, sal_True );
794         aTbxIMapDlg1.CheckItem( TBI_ACTIVE, !rInfo.bActivated );
795         aTbxIMapDlg1.EnableItem( TBI_MACRO, sal_True );
796         aTbxIMapDlg1.EnableItem( TBI_PROPERTY, sal_True );
797 
798         aFtURL.Enable();
799         maURLBox.Enable();
800         aFtText.Enable();
801         aEdtText.Enable();
802         maFtTarget.Enable();
803         maCbbTarget.Enable();
804 
805         aStbStatus.SetItemText( 1, rInfo.aMarkURL );
806 
807         if ( maURLBox.GetText() != rInfo.aMarkURL )
808             maURLBox.SetText( rInfo.aMarkURL );
809 
810         if ( aEdtText.GetText() != rInfo.aMarkAltText )
811             aEdtText.SetText( rInfo.aMarkAltText );
812 
813         if ( !rInfo.aMarkTarget.Len() )
814             maCbbTarget.SetText( DEFINE_CONST_UNICODE( SELF_TARGET ) );
815         else
816             maCbbTarget.SetText(  rInfo.aMarkTarget );
817     }
818 
819     return 0;
820 }
821 
822 /*************************************************************************
823 |*
824 |*
825 |*
826 \************************************************************************/
827 
IMPL_LINK(SvxIMapDlg,MousePosHdl,IMapWindow *,pWnd)828 IMPL_LINK( SvxIMapDlg, MousePosHdl, IMapWindow*, pWnd )
829 {
830     String aStr;
831     const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
832     const Point& rMousePos = pWnd->GetMousePos();
833     LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
834     const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
835 
836     aStr.Assign( GetUnitString( rMousePos.X(), eFieldUnit, cSep ) );
837     aStr.Append( DEFINE_CONST_UNICODE( " / " ) );
838     aStr.Append( GetUnitString( rMousePos.Y(), eFieldUnit, cSep ) );
839 
840     aStbStatus.SetItemText( 2, aStr );
841 
842     return 0L;
843 }
844 
845 /*************************************************************************
846 |*
847 |*
848 |*
849 \************************************************************************/
850 
IMPL_LINK(SvxIMapDlg,GraphSizeHdl,IMapWindow *,pWnd)851 IMPL_LINK( SvxIMapDlg, GraphSizeHdl, IMapWindow*, pWnd )
852 {
853     String aStr;
854     const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
855     const Size& rSize = pWnd->GetGraphicSize();
856     LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
857     const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
858 
859     aStr.Assign( GetUnitString( rSize.Width(), eFieldUnit, cSep ) );
860     aStr.Append( DEFINE_CONST_UNICODE( " x " ) );
861     aStr.Append( GetUnitString( rSize.Height(), eFieldUnit, cSep ) );
862 
863     aStbStatus.SetItemText( 3, aStr );
864 
865     return 0L;
866 }
867 
868 /*************************************************************************
869 |*
870 |*
871 |*
872 \************************************************************************/
873 
IMPL_LINK(SvxIMapDlg,URLModifyHdl,void *,EMPTYARG)874 IMPL_LINK( SvxIMapDlg, URLModifyHdl, void*, EMPTYARG )
875 {
876     NotifyInfo  aNewInfo;
877 
878     aNewInfo.aMarkURL = maURLBox.GetText();
879     aNewInfo.aMarkAltText = aEdtText.GetText();
880     aNewInfo.aMarkTarget = maCbbTarget.GetText();
881 
882     pIMapWnd->ReplaceActualIMapInfo( aNewInfo );
883 
884     return 0;
885 }
886 
887 
888 /*************************************************************************
889 |*
890 |*
891 |*
892 \************************************************************************/
893 
IMPL_LINK(SvxIMapDlg,URLLoseFocusHdl,void *,EMPTYARG)894 IMPL_LINK( SvxIMapDlg, URLLoseFocusHdl, void*, EMPTYARG )
895 {
896     NotifyInfo      aNewInfo;
897     const String    aURLText( maURLBox.GetText() );
898     const String    aTargetText( maCbbTarget.GetText() );
899 
900     if ( aURLText.Len() )
901     {
902         String aBase = GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
903         aNewInfo.aMarkURL = ::URIHelper::SmartRel2Abs( INetURLObject(aBase), aURLText, URIHelper::GetMaybeFileHdl(), true, false,
904                                                         INetURLObject::WAS_ENCODED,
905                                                         INetURLObject::DECODE_UNAMBIGUOUS );
906     }
907     else
908         aNewInfo.aMarkURL = aURLText;
909 
910     aNewInfo.aMarkAltText = aEdtText.GetText();
911 
912     if ( !aTargetText.Len() )
913         aNewInfo.aMarkTarget = DEFINE_CONST_UNICODE( SELF_TARGET );
914     else
915         aNewInfo.aMarkTarget = aTargetText;
916 
917     pIMapWnd->ReplaceActualIMapInfo( aNewInfo );
918 
919     return 0;
920 }
921 
922 
923 /*************************************************************************
924 |*
925 |*
926 |*
927 \************************************************************************/
928 
IMPL_LINK(SvxIMapDlg,UpdateHdl,Timer *,EMPTYARG)929 IMPL_LINK( SvxIMapDlg, UpdateHdl, Timer*, EMPTYARG )
930 {
931     pOwnData->aTimer.Stop();
932 
933     if ( pOwnData->pUpdateEditingObject != pCheckObj )
934     {
935         if ( pIMapWnd->IsChanged() &&
936              ( QueryBox( this, WB_YES_NO | WB_DEF_YES,
937              String( SVX_RES( STR_IMAPDLG_SAVE ) ) ).Execute() == RET_YES ) )
938         {
939             DoSave();
940         }
941 
942         SetGraphic( pOwnData->aUpdateGraphic );
943         SetImageMap( pOwnData->aUpdateImageMap );
944         SetTargetList( pOwnData->aUpdateTargetList );
945         SetEditingObject( pOwnData->pUpdateEditingObject );
946 
947         // Nach Wechsel => default Selektion
948         aTbxIMapDlg1.CheckItem( TBI_SELECT, sal_True );
949         pIMapWnd->SetEditMode( sal_True );
950     }
951 
952     // die in der Update-Methode kopierte Liste wieder loeschen
953     for( String* pStr = pOwnData->aUpdateTargetList.First(); pStr; pStr = pOwnData->aUpdateTargetList.Next() )
954         delete pStr;
955 
956     pOwnData->aUpdateTargetList.Clear();
957 
958     GetBindings().Invalidate( SID_IMAP_EXEC );
959 
960     return 0L;
961 }
962 
963 
964 /*************************************************************************
965 |*
966 |*
967 |*
968 \************************************************************************/
969 
IMPL_LINK(SvxIMapDlg,StateHdl,IMapWindow *,pWnd)970 IMPL_LINK( SvxIMapDlg, StateHdl, IMapWindow*, pWnd )
971 {
972     const SdrObject*    pObj = pWnd->GetSelectedSdrObject();
973     const SdrModel*     pModel = pWnd->GetSdrModel();
974     const SdrView*      pView = pWnd->GetSdrView();
975     const sal_Bool          bPolyEdit = ( pObj != NULL ) && pObj->ISA( SdrPathObj );
976     const sal_Bool          bDrawEnabled = !( bPolyEdit && aTbxIMapDlg1.IsItemChecked( TBI_POLYEDIT ) );
977 
978     aTbxIMapDlg1.EnableItem( TBI_APPLY, pOwnData->bExecState && pWnd->IsChanged() );
979 
980     aTbxIMapDlg1.EnableItem( TBI_SELECT, bDrawEnabled );
981     aTbxIMapDlg1.EnableItem( TBI_RECT, bDrawEnabled );
982     aTbxIMapDlg1.EnableItem( TBI_CIRCLE, bDrawEnabled );
983     aTbxIMapDlg1.EnableItem( TBI_POLY, bDrawEnabled );
984     aTbxIMapDlg1.EnableItem( TBI_FREEPOLY, bDrawEnabled );
985 
986     // BezierEditor-Stati
987     aTbxIMapDlg1.EnableItem( TBI_POLYEDIT, bPolyEdit );
988     aTbxIMapDlg1.EnableItem( TBI_POLYMOVE, !bDrawEnabled );
989     aTbxIMapDlg1.EnableItem( TBI_POLYINSERT, !bDrawEnabled );
990     aTbxIMapDlg1.EnableItem( TBI_POLYDELETE, !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
991 
992     // Undo/Redo
993     aTbxIMapDlg1.EnableItem( TBI_UNDO, pModel->GetUndoActionCount() > 0 );
994     aTbxIMapDlg1.EnableItem( TBI_REDO, pModel->GetRedoActionCount() > 0 );
995 
996     if ( bPolyEdit )
997     {
998         sal_uInt16 nId = 0;
999 
1000         switch( pWnd->GetPolyEditMode() )
1001         {
1002             case( SID_BEZIER_MOVE ): nId = TBI_POLYMOVE; break;
1003             case( SID_BEZIER_INSERT ): nId = TBI_POLYINSERT; break;
1004 
1005             default:
1006             break;
1007         }
1008 
1009         aTbxIMapDlg1.CheckItem( nId, sal_True );
1010     }
1011     else
1012     {
1013         aTbxIMapDlg1.CheckItem( TBI_POLYEDIT, sal_False );
1014         aTbxIMapDlg1.CheckItem( TBI_POLYMOVE, sal_True );
1015         aTbxIMapDlg1.CheckItem( TBI_POLYINSERT, sal_False );
1016         pWnd->SetPolyEditMode( 0 );
1017     }
1018 
1019     return 0L;
1020 }
1021 
1022 /*************************************************************************
1023 |*
1024 |*
1025 |*
1026 \************************************************************************/
1027 
IMPL_LINK(SvxIMapDlg,MiscHdl,void *,EMPTYARG)1028 IMPL_LINK( SvxIMapDlg, MiscHdl, void*, EMPTYARG )
1029 {
1030     SvtMiscOptions aMiscOptions;
1031     aTbxIMapDlg1.SetOutStyle( aMiscOptions.GetToolboxStyle() );
1032 
1033     return 0L;
1034 }
1035 
ApplyImageList()1036 void SvxIMapDlg::ApplyImageList()
1037 {
1038     bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
1039 
1040     ImageList& rImgLst = bHighContrast ? maImageListH : maImageList;
1041 
1042     aTbxIMapDlg1.SetImageList( rImgLst );
1043 }
1044 
DataChanged(const DataChangedEvent & rDCEvt)1045 void SvxIMapDlg::DataChanged( const DataChangedEvent& rDCEvt )
1046 {
1047     SfxModelessDialog::DataChanged( rDCEvt );
1048 
1049     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1050             ApplyImageList();
1051 }
1052