Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / svx / source / dialog / imapdlg.cxx
blob170ff2c905439ef7158211cfe1797283c0b5aeec
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 <vcl/errinf.hxx>
21 #include <tools/urlobj.hxx>
22 #include <unotools/ucbstreamhelper.hxx>
23 #include <svl/eitem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <sfx2/module.hxx>
26 #include <sfx2/filedlghelper.hxx>
27 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
28 #include <svl/urihelper.hxx>
29 #include <svtools/ehdl.hxx>
30 #include <svtools/inettbc.hxx>
31 #include <svtools/sfxecode.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/objsh.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <unotools/localedatawrapper.hxx>
36 #include <vcl/weld.hxx>
37 #include <svx/imapdlg.hxx>
38 #include <svx/dialmgr.hxx>
39 #include <svx/strings.hrc>
40 #include <svx/svxids.hrc>
41 #include "imapwnd.hxx"
42 #include "imapimp.hxx"
43 #include <svx/svdopath.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/settings.hxx>
46 #include <osl/diagnose.h>
47 #include "dlgunit.hxx"
48 #include <memory>
50 constexpr OUString SELF_TARGET = u"_self"_ustr;
51 constexpr OUString IMAP_CERN_FILTER = u"MAP - CERN"_ustr;
52 constexpr OUString IMAP_NCSA_FILTER = u"MAP - NCSA"_ustr;
53 constexpr OUString IMAP_BINARY_FILTER = u"SIP - StarView ImageMap"_ustr;
54 constexpr OUStringLiteral IMAP_ALL_TYPE = u"*.*";
55 constexpr OUString IMAP_BINARY_TYPE = u"*.sip"_ustr;
56 constexpr OUString IMAP_CERN_TYPE = u"*.map"_ustr;
57 constexpr OUString IMAP_NCSA_TYPE = u"*.map"_ustr;
59 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID( SvxIMapDlgChildWindow, SID_IMAP );
61 // ControllerItem
63 SvxIMapDlgItem::SvxIMapDlgItem( SvxIMapDlg& rIMapDlg, SfxBindings& rBindings ) :
64 SfxControllerItem ( SID_IMAP_EXEC, rBindings ),
65 rIMap ( rIMapDlg )
69 void SvxIMapDlgItem::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState /*eState*/,
70 const SfxPoolItem* pItem )
72 if ( ( nSID == SID_IMAP_EXEC ) && pItem )
74 const SfxBoolItem* pStateItem = dynamic_cast<const SfxBoolItem*>( pItem );
75 assert(pStateItem); //SfxBoolItem expected
76 if (pStateItem)
78 // Disable Float if possible
79 rIMap.SetExecState( !pStateItem->GetValue() );
84 SvxIMapDlgChildWindow::SvxIMapDlgChildWindow(vcl::Window* _pParent, sal_uInt16 nId,
85 SfxBindings* pBindings,
86 SfxChildWinInfo const * pInfo)
87 : SfxChildWindow( _pParent, nId )
89 SetController(std::make_shared<SvxIMapDlg>(pBindings, this, _pParent->GetFrameWeld()));
90 SvxIMapDlg* pDlg = static_cast<SvxIMapDlg*>(GetController().get());
91 pDlg->Initialize( pInfo );
94 void SvxIMapDlgChildWindow::UpdateIMapDlg( const Graphic& rGraphic, const ImageMap* pImageMap,
95 const TargetList* pTargetList, void* pEditingObj )
97 SvxIMapDlg* pDlg = GetIMapDlg();
98 if (pDlg)
99 pDlg->UpdateLink(rGraphic, pImageMap, pTargetList, pEditingObj);
102 SvxIMapDlg::SvxIMapDlg(SfxBindings *_pBindings, SfxChildWindow *pCW, weld::Window* _pParent)
103 : SfxModelessDialogController(_pBindings, pCW, _pParent, u"svx/ui/imapdialog.ui"_ustr, u"ImapDialog"_ustr)
104 , pCheckObj(nullptr)
105 , aIMapItem(*this, *_pBindings)
106 , m_xIMapWnd(new IMapWindow(_pBindings->GetActiveFrame(), m_xDialog.get()))
107 , m_xTbxIMapDlg1(m_xBuilder->weld_toolbar(u"toolbar"_ustr))
108 , m_xFtURL(m_xBuilder->weld_label(u"urlft"_ustr))
109 , m_xURLBox(new SvtURLBox(m_xBuilder->weld_combo_box(u"url"_ustr)))
110 , m_xFtText(m_xBuilder->weld_label(u"textft"_ustr))
111 , m_xEdtText(m_xBuilder->weld_entry(u"text"_ustr))
112 , m_xFtTarget(m_xBuilder->weld_label(u"targetft"_ustr))
113 , m_xCbbTarget(m_xBuilder->weld_combo_box(u"target"_ustr))
114 , m_xCancelBtn(m_xBuilder->weld_button(u"cancel"_ustr))
115 , m_xStbStatus1(m_xBuilder->weld_label(u"statusurl"_ustr))
116 , m_xStbStatus2(m_xBuilder->weld_label(u"statuspos"_ustr))
117 , m_xStbStatus3(m_xBuilder->weld_label(u"statussize"_ustr))
118 , m_xIMapWndWeld(new weld::CustomWeld(*m_xBuilder, u"container"_ustr, *m_xIMapWnd))
121 m_xTbxIMapDlg1->insert_separator(4, u"sep1"_ustr);
122 m_xTbxIMapDlg1->insert_separator(10, u"sep2"_ustr);
123 m_xTbxIMapDlg1->insert_separator(15, u"sep3"_ustr);
124 m_xTbxIMapDlg1->insert_separator(18, u"sel4"_ustr);
126 //lock this down so it doesn't jump around in size
127 //as entries are added later on
128 TargetList aTmpList;
129 SfxFrame::GetDefaultTargetList(aTmpList);
130 for (const OUString & s : aTmpList)
131 m_xCbbTarget->append_text(s);
132 Size aPrefSize(m_xCbbTarget->get_preferred_size());
133 m_xCbbTarget->set_size_request(aPrefSize.Width(), -1);
134 m_xCbbTarget->clear();
136 m_xIMapWnd->Show();
138 pOwnData.reset(new IMapOwnData);
140 m_xIMapWnd->SetInfoLink( LINK( this, SvxIMapDlg, InfoHdl ) );
141 m_xIMapWnd->SetMousePosLink( LINK( this, SvxIMapDlg, MousePosHdl ) );
142 m_xIMapWnd->SetGraphSizeLink( LINK( this, SvxIMapDlg, GraphSizeHdl ) );
143 m_xIMapWnd->SetUpdateLink( LINK( this, SvxIMapDlg, StateHdl ) );
145 m_xURLBox->connect_changed( LINK( this, SvxIMapDlg, URLModifyHdl ) );
146 m_xURLBox->connect_focus_out( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
147 m_xEdtText->connect_changed( LINK( this, SvxIMapDlg, EntryModifyHdl ) );
148 m_xCbbTarget->connect_focus_out( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
150 m_xTbxIMapDlg1->connect_clicked( LINK( this, SvxIMapDlg, TbxClickHdl ) );
151 OUString sSelect(u"TBI_SELECT"_ustr);
152 m_xTbxIMapDlg1->set_item_active(sSelect, true);
153 TbxClickHdl(sSelect);
155 m_xStbStatus1->set_size_request(120, -1);
156 const int nWidth = m_xStbStatus1->get_pixel_size(u" 9999,99 cm / 9999,99 cm "_ustr).Width();
157 m_xStbStatus2->set_size_request(nWidth, -1);
158 m_xStbStatus3->set_size_request(nWidth, -1);
160 m_xFtURL->set_sensitive(false);
161 m_xURLBox->set_sensitive(false);
162 m_xFtText->set_sensitive(false);
163 m_xEdtText->set_sensitive(false);
164 m_xFtTarget->set_sensitive(false);
165 m_xCbbTarget->set_sensitive(false);
166 pOwnData->bExecState = false;
168 pOwnData->aIdle.SetInvokeHandler( LINK( this, SvxIMapDlg, UpdateHdl ) );
170 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_ACTIVE"_ustr, false);
171 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_MACRO"_ustr, false );
172 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_PROPERTY"_ustr, false );
174 m_xCancelBtn->connect_clicked(LINK(this, SvxIMapDlg, CancelHdl));
177 SvxIMapDlg::~SvxIMapDlg()
179 m_xIMapWnd->SetUpdateLink( Link<GraphCtrl*,void>() );
180 m_xIMapWnd.reset();
183 IMPL_LINK_NOARG(SvxIMapDlg, CancelHdl, weld::Button&, void)
185 bool bRet = true;
187 if ( m_xTbxIMapDlg1->get_item_sensitive(u"TBI_APPLY"_ustr) )
189 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), u"svx/ui/querymodifyimagemapchangesdialog.ui"_ustr));
190 std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog(u"QueryModifyImageMapChangesDialog"_ustr));
191 const tools::Long nRet = xQBox->run();
193 if( nRet == RET_YES )
195 SfxBoolItem aBoolItem( SID_IMAP_EXEC, true );
196 GetBindings().GetDispatcher()->ExecuteList(SID_IMAP_EXEC,
197 SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
198 { &aBoolItem });
200 else if( nRet == RET_CANCEL )
201 bRet = false;
203 else if( m_xIMapWnd->IsChanged() )
205 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), u"svx/ui/querysaveimagemapchangesdialog.ui"_ustr));
206 std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog(u"QuerySaveImageMapChangesDialog"_ustr));
207 const tools::Long nRet = xQBox->run();
209 if( nRet == RET_YES )
210 bRet = DoSave();
211 else if( nRet == RET_CANCEL )
212 bRet = false;
215 if (bRet)
216 m_xDialog->response(RET_CANCEL);
219 // Enabled or disable all Controls
221 void SvxIMapDlg::SetExecState( bool bEnable )
223 pOwnData->bExecState = bEnable;
226 const ImageMap& SvxIMapDlg::GetImageMap() const
228 return m_xIMapWnd->GetImageMap();
231 void SvxIMapDlg::SetTargetList( const TargetList& rTargetList )
233 m_xIMapWnd->SetTargetList( rTargetList );
235 m_xCbbTarget->clear();
237 for (const OUString & s : rTargetList)
238 m_xCbbTarget->append_text(s);
241 void SvxIMapDlg::UpdateLink( const Graphic& rGraphic, const ImageMap* pImageMap,
242 const TargetList* pTargetList, void* pEditingObj )
244 pOwnData->aUpdateGraphic = rGraphic;
246 if ( pImageMap )
247 pOwnData->aUpdateImageMap = *pImageMap;
248 else
249 pOwnData->aUpdateImageMap.ClearImageMap();
251 pOwnData->pUpdateEditingObject = pEditingObj;
253 // Delete UpdateTargetList, because this method can still be called several
254 // times before the update timer is turned on
256 // TargetList must be copied, since it is owned by the caller and can be
257 // deleted immediately after this call the copied list will be deleted
258 // again in the handler
259 if( pTargetList )
260 pOwnData->aUpdateTargetList = *pTargetList;
261 else
262 pOwnData->aUpdateTargetList.clear();
264 pOwnData->aIdle.Start();
268 // Click-handler for ToolBox
270 IMPL_LINK(SvxIMapDlg, TbxClickHdl, const OUString&, rNewItemId, void)
272 if (rNewItemId == "TBI_APPLY")
274 URLLoseFocusHdl(*m_xCbbTarget);
275 SfxBoolItem aBoolItem( SID_IMAP_EXEC, true );
276 GetBindings().GetDispatcher()->ExecuteList(SID_IMAP_EXEC,
277 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
278 { &aBoolItem });
280 else if (rNewItemId == "TBI_OPEN")
281 DoOpen();
282 else if (rNewItemId == "TBI_SAVEAS")
283 DoSave();
284 else if (rNewItemId == "TBI_CLOSE")
285 CancelHdl(*m_xCancelBtn);
286 else if (rNewItemId == "TBI_SELECT")
288 SetActiveTool( rNewItemId );
289 m_xIMapWnd->SetEditMode( true );
291 else if (rNewItemId == "TBI_RECT")
293 SetActiveTool( rNewItemId );
294 m_xIMapWnd->SetObjKind( SdrObjKind::Rectangle );
296 else if (rNewItemId == "TBI_CIRCLE")
298 SetActiveTool( rNewItemId );
299 m_xIMapWnd->SetObjKind( SdrObjKind::CircleOrEllipse );
301 else if (rNewItemId == "TBI_POLY")
303 SetActiveTool( rNewItemId );
304 m_xIMapWnd->SetObjKind( SdrObjKind::Polygon );
306 else if (rNewItemId == "TBI_FREEPOLY")
308 SetActiveTool( rNewItemId );
309 m_xIMapWnd->SetObjKind( SdrObjKind::FreehandFill );
311 else if (rNewItemId == "TBI_ACTIVE")
313 URLLoseFocusHdl(*m_xCbbTarget);
314 bool bNewState = !m_xTbxIMapDlg1->get_item_active(rNewItemId);
315 m_xTbxIMapDlg1->set_item_active(rNewItemId, bNewState);
316 m_xIMapWnd->SetCurrentObjState( !bNewState );
318 else if (rNewItemId == "TBI_MACRO")
319 m_xIMapWnd->DoMacroAssign();
320 else if (rNewItemId == "TBI_PROPERTY")
321 m_xIMapWnd->DoPropertyDialog();
322 else if (rNewItemId == "TBI_POLYEDIT")
324 SetActiveTool( rNewItemId );
325 m_xIMapWnd->SetPolyEditMode( m_xTbxIMapDlg1->get_item_active(rNewItemId) ? SID_BEZIER_MOVE : 0 );
327 else if (rNewItemId == "TBI_POLYMOVE")
329 SetActiveTool( rNewItemId );
330 m_xIMapWnd->SetPolyEditMode( SID_BEZIER_MOVE );
332 else if (rNewItemId == "TBI_POLYINSERT")
334 SetActiveTool( rNewItemId );
335 m_xIMapWnd->SetPolyEditMode( SID_BEZIER_INSERT );
337 else if (rNewItemId == "TBI_POLYDELETE")
339 SetActiveTool( rNewItemId );
340 m_xIMapWnd->GetSdrView()->DeleteMarkedPoints();
342 else if (rNewItemId == "TBI_UNDO")
344 URLLoseFocusHdl(*m_xCbbTarget);
345 m_xIMapWnd->GetSdrModel()->Undo();
347 else if (rNewItemId == "TBI_REDO")
349 URLLoseFocusHdl(*m_xCbbTarget);
350 m_xIMapWnd->GetSdrModel()->Redo();
354 void SvxIMapDlg::DoOpen()
356 ::sfx2::FileDialogHelper aDlg(
357 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
358 FileDialogFlags::NONE, m_xDialog.get());
360 ImageMap aLoadIMap;
361 const OUString aFilter(SvxResId(RID_SVXSTR_IMAP_ALL_FILTER));
363 aDlg.AddFilter( aFilter, IMAP_ALL_TYPE );
364 aDlg.AddFilter( IMAP_CERN_FILTER, IMAP_CERN_TYPE );
365 aDlg.AddFilter( IMAP_NCSA_FILTER, IMAP_NCSA_TYPE );
366 aDlg.AddFilter( IMAP_BINARY_FILTER, IMAP_BINARY_TYPE );
368 aDlg.SetCurrentFilter( aFilter );
369 aDlg.SetContext(sfx2::FileDialogHelper::ImageMap);
371 if( aDlg.Execute() != ERRCODE_NONE )
372 return;
374 INetURLObject aURL( aDlg.GetPath() );
375 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
376 std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
378 if( pIStm )
380 aLoadIMap.Read( *pIStm, IMapFormat::Detect );
382 if( pIStm->GetError() )
384 SfxErrorContext eEC(ERRCTX_ERROR, m_xDialog.get());
385 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
387 else
388 m_xIMapWnd->SetImageMap( aLoadIMap );
391 m_xIMapWnd->Invalidate();
394 bool SvxIMapDlg::DoSave()
396 ::sfx2::FileDialogHelper aDlg(
397 css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE,
398 FileDialogFlags::NONE, m_xDialog.get());
400 const OUString aBinFilter( IMAP_BINARY_FILTER );
401 const OUString aCERNFilter( IMAP_CERN_FILTER );
402 const OUString aNCSAFilter( IMAP_NCSA_FILTER );
403 SdrModel* pModel = m_xIMapWnd->GetSdrModel();
404 const bool bChanged = pModel->IsChanged();
405 bool bRet = false;
407 aDlg.AddFilter( aCERNFilter, IMAP_CERN_TYPE );
408 aDlg.AddFilter( aNCSAFilter, IMAP_NCSA_TYPE );
409 aDlg.AddFilter( aBinFilter, IMAP_BINARY_TYPE );
411 aDlg.SetCurrentFilter( aCERNFilter );
412 aDlg.SetContext(sfx2::FileDialogHelper::ImageMap);
414 if( aDlg.Execute() == ERRCODE_NONE )
416 const OUString aFilter( aDlg.GetCurrentFilter() );
417 OUString aExt;
418 IMapFormat nFormat;
420 if ( aFilter == aBinFilter )
422 nFormat = IMapFormat::Binary;
423 aExt = "sip";
425 else if ( aFilter == aCERNFilter )
427 nFormat = IMapFormat::CERN;
428 aExt = "map";
430 else if ( aFilter == aNCSAFilter )
432 nFormat = IMapFormat::NCSA;
433 aExt = "map";
435 else
437 return false;
440 INetURLObject aURL( aDlg.GetPath() );
442 if( aURL.GetProtocol() == INetProtocol::NotValid )
444 OSL_FAIL( "invalid URL" );
446 else
448 if( aURL.getExtension().isEmpty() )
449 aURL.setExtension( aExt );
451 std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC ));
452 if( pOStm )
454 m_xIMapWnd->GetImageMap().Write( *pOStm, nFormat );
456 if( pOStm->GetError() )
457 ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
459 pOStm.reset();
460 pModel->SetChanged( bChanged );
461 bRet = true;
466 return bRet;
469 void SvxIMapDlg::SetActiveTool(std::u16string_view rId)
471 m_xTbxIMapDlg1->set_item_active(u"TBI_SELECT"_ustr, rId == u"TBI_SELECT");
472 m_xTbxIMapDlg1->set_item_active(u"TBI_RECT"_ustr, rId == u"TBI_RECT");
473 m_xTbxIMapDlg1->set_item_active(u"TBI_CIRCLE"_ustr, rId == u"TBI_CIRCLE");
474 m_xTbxIMapDlg1->set_item_active(u"TBI_POLY"_ustr, rId == u"TBI_POLY");
475 m_xTbxIMapDlg1->set_item_active(u"TBI_FREEPOLY"_ustr, rId == u"TBI_FREEPOLY");
477 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYINSERT"_ustr, rId == u"TBI_POLYINSERT");
478 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYDELETE"_ustr, false);
480 bool bMove = rId == u"TBI_POLYMOVE"
481 || ( rId == u"TBI_POLYEDIT"
482 && !m_xTbxIMapDlg1->get_item_active(u"TBI_POLYINSERT"_ustr)
483 && !m_xTbxIMapDlg1->get_item_active(u"TBI_POLYDELETE"_ustr) );
485 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYMOVE"_ustr, bMove );
487 bool bEditMode = ( rId == u"TBI_POLYEDIT" )
488 || ( rId == u"TBI_POLYMOVE")
489 || ( rId == u"TBI_POLYINSERT")
490 || ( rId == u"TBI_POLYDELETE" );
492 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYEDIT"_ustr, bEditMode);
495 IMPL_LINK( SvxIMapDlg, InfoHdl, IMapWindow&, rWnd, void )
497 const NotifyInfo& rInfo = rWnd.GetInfo();
499 if ( rInfo.bNewObj )
501 if (!rInfo.aMarkURL.isEmpty() && ( m_xURLBox->find_text(rInfo.aMarkURL) == -1))
502 m_xURLBox->append_text(rInfo.aMarkURL);
504 m_xURLBox->set_entry_text(rInfo.aMarkURL);
505 m_xEdtText->set_text(rInfo.aMarkAltText);
507 if ( rInfo.aMarkTarget.isEmpty() )
508 m_xCbbTarget->set_entry_text( SELF_TARGET );
509 else
510 m_xCbbTarget->set_entry_text( rInfo.aMarkTarget );
513 if ( !rInfo.bOneMarked )
515 m_xTbxIMapDlg1->set_item_active(u"TBI_ACTIVE"_ustr, false);
516 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_ACTIVE"_ustr, false);
517 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_MACRO"_ustr, false);
518 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_PROPERTY"_ustr, false);
519 m_xStbStatus1->set_label(OUString());
521 m_xFtURL->set_sensitive(false);
522 m_xURLBox->set_sensitive(false);
523 m_xFtText->set_sensitive(false);
524 m_xEdtText->set_sensitive(false);
525 m_xFtTarget->set_sensitive(false);
526 m_xCbbTarget->set_sensitive(false);
528 m_xURLBox->set_entry_text( u""_ustr );
529 m_xEdtText->set_text( u""_ustr );
531 else
533 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_ACTIVE"_ustr, true);
534 m_xTbxIMapDlg1->set_item_active(u"TBI_ACTIVE"_ustr, !rInfo.bActivated );
535 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_MACRO"_ustr, true);
536 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_PROPERTY"_ustr, true);
538 m_xFtURL->set_sensitive(true);
539 m_xURLBox->set_sensitive(true);
540 m_xFtText->set_sensitive(true);
541 m_xEdtText->set_sensitive(true);
542 m_xFtTarget->set_sensitive(true);
543 m_xCbbTarget->set_sensitive(true);
545 m_xStbStatus1->set_label(rInfo.aMarkURL);
547 if ( m_xURLBox->get_active_text() != rInfo.aMarkURL )
548 m_xURLBox->set_entry_text( rInfo.aMarkURL );
550 if ( m_xEdtText->get_text() != rInfo.aMarkAltText )
551 m_xEdtText->set_text( rInfo.aMarkAltText );
553 if ( rInfo.aMarkTarget.isEmpty() )
554 m_xCbbTarget->set_entry_text( SELF_TARGET );
555 else
556 m_xCbbTarget->set_entry_text( rInfo.aMarkTarget );
560 IMPL_LINK( SvxIMapDlg, MousePosHdl, GraphCtrl*, pWnd, void )
562 const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
563 const Point& rMousePos = pWnd->GetMousePos();
564 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
565 const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
567 OUString aStr = GetUnitString( rMousePos.X(), eFieldUnit, cSep ) +
568 " / " + GetUnitString( rMousePos.Y(), eFieldUnit, cSep );
570 m_xStbStatus2->set_label(aStr);
573 IMPL_LINK( SvxIMapDlg, GraphSizeHdl, GraphCtrl*, pWnd, void )
575 const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
576 const Size& rSize = pWnd->GetGraphicSize();
577 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
578 const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
580 OUString aStr = GetUnitString( rSize.Width(), eFieldUnit, cSep ) +
581 " x " + GetUnitString( rSize.Height(), eFieldUnit, cSep );
583 m_xStbStatus3->set_label(aStr);
586 void SvxIMapDlg::URLModify()
588 NotifyInfo aNewInfo;
590 aNewInfo.aMarkURL = m_xURLBox->get_active_text();
591 aNewInfo.aMarkAltText = m_xEdtText->get_text();
592 aNewInfo.aMarkTarget = m_xCbbTarget->get_active_text();
594 m_xIMapWnd->ReplaceActualIMapInfo( aNewInfo );
597 IMPL_LINK_NOARG(SvxIMapDlg, URLModifyHdl, weld::ComboBox&, void)
599 URLModify();
602 IMPL_LINK_NOARG(SvxIMapDlg, EntryModifyHdl, weld::Entry&, void)
604 URLModify();
607 IMPL_LINK_NOARG(SvxIMapDlg, URLLoseFocusHdl, weld::Widget&, void)
609 NotifyInfo aNewInfo;
610 const OUString aURLText( m_xURLBox->get_active_text() );
611 const OUString aTargetText( m_xCbbTarget->get_active_text() );
613 if ( !aURLText.isEmpty() )
615 OUString aBase = GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
616 aNewInfo.aMarkURL = ::URIHelper::SmartRel2Abs( INetURLObject(aBase), aURLText, URIHelper::GetMaybeFileHdl(), true, false,
617 INetURLObject::EncodeMechanism::WasEncoded,
618 INetURLObject::DecodeMechanism::Unambiguous );
620 else
621 aNewInfo.aMarkURL = aURLText;
623 aNewInfo.aMarkAltText = m_xEdtText->get_text();
625 if ( aTargetText.isEmpty() )
626 aNewInfo.aMarkTarget = SELF_TARGET;
627 else
628 aNewInfo.aMarkTarget = aTargetText;
630 m_xIMapWnd->ReplaceActualIMapInfo( aNewInfo );
633 IMPL_LINK_NOARG(SvxIMapDlg, UpdateHdl, Timer *, void)
635 pOwnData->aIdle.Stop();
637 if ( pOwnData->pUpdateEditingObject != pCheckObj )
639 if (m_xIMapWnd->IsChanged())
641 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), u"svx/ui/querysaveimagemapchangesdialog.ui"_ustr));
642 std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog(u"QuerySaveImageMapChangesDialog"_ustr));
643 if (xQBox->run() == RET_YES)
645 DoSave();
649 m_xIMapWnd->SetGraphic( pOwnData->aUpdateGraphic );
650 m_xIMapWnd->SetImageMap( pOwnData->aUpdateImageMap );
651 SetTargetList( pOwnData->aUpdateTargetList );
652 pCheckObj = pOwnData->pUpdateEditingObject;
654 // After changes => default selection
655 m_xTbxIMapDlg1->set_item_active(u"TBI_SELECT"_ustr, true);
656 m_xIMapWnd->SetEditMode( true );
659 // Delete the copied list again in the Update method
660 pOwnData->aUpdateTargetList.clear();
662 GetBindings().Invalidate( SID_IMAP_EXEC );
663 m_xIMapWnd->QueueIdleUpdate();
666 IMPL_LINK( SvxIMapDlg, StateHdl, GraphCtrl*, pWnd, void )
668 const SdrObject* pObj = pWnd->GetSelectedSdrObject();
669 const SdrModel* pModel = pWnd->GetSdrModel();
670 const SdrView* pView = pWnd->GetSdrView();
671 const bool bPolyEdit = ( pObj != nullptr ) && dynamic_cast<const SdrPathObj*>( pObj) != nullptr;
672 const bool bDrawEnabled = !( bPolyEdit && m_xTbxIMapDlg1->get_item_active(u"TBI_POLYEDIT"_ustr) );
674 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_APPLY"_ustr, pOwnData->bExecState && pWnd->IsChanged() );
676 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_SELECT"_ustr, bDrawEnabled);
677 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_RECT"_ustr, bDrawEnabled);
678 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_CIRCLE"_ustr, bDrawEnabled);
679 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_POLY"_ustr, bDrawEnabled);
680 m_xTbxIMapDlg1->set_item_sensitive(u"TBI_FREEPOLY"_ustr, bDrawEnabled);
682 // BezierEditor State
683 m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYEDIT"_ustr, bPolyEdit );
684 m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYMOVE"_ustr, !bDrawEnabled );
685 m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYINSERT"_ustr, !bDrawEnabled );
686 m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYDELETE"_ustr, !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
688 // Undo/Redo
689 m_xTbxIMapDlg1->set_item_sensitive( u"TBI_UNDO"_ustr, pModel->HasUndoActions() );
690 m_xTbxIMapDlg1->set_item_sensitive( u"TBI_REDO"_ustr, pModel->HasRedoActions() );
692 if ( bPolyEdit )
694 switch( pWnd->GetPolyEditMode() )
696 case SID_BEZIER_MOVE:
697 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYMOVE"_ustr, true);
698 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYINSERT"_ustr, false);
699 break;
700 case SID_BEZIER_INSERT:
701 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYINSERT"_ustr, true);
702 m_xTbxIMapDlg1->set_item_active(u"TBI_POLYMOVE"_ustr, false);
703 break;
704 default:
705 break;
708 else
710 m_xTbxIMapDlg1->set_item_active( u"TBI_POLYEDIT"_ustr, false );
711 m_xTbxIMapDlg1->set_item_active( u"TBI_POLYMOVE"_ustr, true);
712 m_xTbxIMapDlg1->set_item_active( u"TBI_POLYINSERT"_ustr, false );
713 pWnd->SetPolyEditMode( 0 );
716 m_xIMapWnd->QueueIdleUpdate();
719 SvxIMapDlg* GetIMapDlg()
721 SfxChildWindow* pWnd = nullptr;
722 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
723 if (pViewFrm && pViewFrm->HasChildWindow(SvxIMapDlgChildWindow::GetChildWindowId()))
724 pWnd = pViewFrm->GetChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
725 return pWnd ? static_cast<SvxIMapDlg*>(pWnd->GetController().get()) : nullptr;
728 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */