Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/dialog/imapdlg.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <vcl/errinf.hxx>
21
#include <tools/stream.hxx>
22
#include <tools/urlobj.hxx>
23
#include <unotools/ucbstreamhelper.hxx>
24
#include <svl/eitem.hxx>
25
#include <sfx2/dispatch.hxx>
26
#include <sfx2/module.hxx>
27
#include <sfx2/filedlghelper.hxx>
28
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29
#include <svl/urihelper.hxx>
30
#include <svtools/ehdl.hxx>
31
#include <svtools/inettbc.hxx>
32
#include <svtools/sfxecode.hxx>
33
#include <sfx2/viewfrm.hxx>
34
#include <sfx2/objsh.hxx>
35
#include <sfx2/docfile.hxx>
36
#include <unotools/localedatawrapper.hxx>
37
#include <vcl/weld/Button.hxx>
38
#include <vcl/weld/Dialog.hxx>
39
#include <vcl/weld/Label.hxx>
40
#include <vcl/weld/MessageDialog.hxx>
41
#include <svx/imapdlg.hxx>
42
#include <svx/dialmgr.hxx>
43
#include <svx/strings.hrc>
44
#include <svx/svxids.hrc>
45
#include "imapwnd.hxx"
46
#include "imapimp.hxx"
47
#include <svx/svdopath.hxx>
48
#include <vcl/svapp.hxx>
49
#include <vcl/settings.hxx>
50
#include <vcl/weld/Builder.hxx>
51
#include <osl/diagnose.h>
52
#include "dlgunit.hxx"
53
#include <memory>
54
55
constexpr OUString SELF_TARGET = u"_self"_ustr;
56
constexpr OUString IMAP_CERN_FILTER = u"MAP - CERN"_ustr;
57
constexpr OUString IMAP_NCSA_FILTER = u"MAP - NCSA"_ustr;
58
constexpr OUString IMAP_BINARY_FILTER = u"SIP - StarView ImageMap"_ustr;
59
constexpr OUStringLiteral IMAP_ALL_TYPE = u"*.*";
60
constexpr OUString IMAP_BINARY_TYPE = u"*.sip"_ustr;
61
constexpr OUString IMAP_CERN_TYPE = u"*.map"_ustr;
62
constexpr OUString IMAP_NCSA_TYPE = u"*.map"_ustr;
63
64
SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID( SvxIMapDlgChildWindow, SID_IMAP );
65
66
// ControllerItem
67
68
SvxIMapDlgItem::SvxIMapDlgItem( SvxIMapDlg& rIMapDlg, SfxBindings& rBindings ) :
69
0
            SfxControllerItem   ( SID_IMAP_EXEC, rBindings ),
70
0
            m_rIMap               ( rIMapDlg )
71
0
{
72
0
}
73
74
void SvxIMapDlgItem::StateChangedAtToolBoxControl( sal_uInt16 nSID, SfxItemState /*eState*/,
75
                                   const SfxPoolItem* pItem )
76
0
{
77
0
    if ( ( nSID == SID_IMAP_EXEC ) && pItem )
78
0
    {
79
0
        const SfxBoolItem* pStateItem = dynamic_cast<const SfxBoolItem*>( pItem  );
80
0
        assert(pStateItem); //SfxBoolItem expected
81
0
        if (pStateItem)
82
0
        {
83
            // Disable Float if possible
84
0
            m_rIMap.SetExecState( !pStateItem->GetValue() );
85
0
        }
86
0
    }
87
0
}
88
89
SvxIMapDlgChildWindow::SvxIMapDlgChildWindow(vcl::Window* _pParent, sal_uInt16 nId,
90
                                             SfxBindings& rBindings, const SfxChildWinInfo& rInfo)
91
0
    : SfxChildWindow(_pParent, nId)
92
0
{
93
0
    SetController(std::make_shared<SvxIMapDlg>(&rBindings, this, _pParent->GetFrameWeld()));
94
0
    SvxIMapDlg* pDlg = static_cast<SvxIMapDlg*>(GetController().get());
95
0
    pDlg->Initialize(rInfo);
96
0
}
97
98
void SvxIMapDlgChildWindow::UpdateIMapDlg( const Graphic& rGraphic, const ImageMap* pImageMap,
99
                                           const TargetList* pTargetList, void* pEditingObj )
100
0
{
101
0
    SvxIMapDlg* pDlg = GetIMapDlg();
102
0
    if (pDlg)
103
0
        pDlg->UpdateLink(rGraphic, pImageMap, pTargetList, pEditingObj);
104
0
}
105
106
SvxIMapDlg::SvxIMapDlg(SfxBindings *_pBindings, SfxChildWindow *pCW, weld::Window* _pParent)
107
0
    : SfxModelessDialogController(_pBindings, pCW, _pParent, u"svx/ui/imapdialog.ui"_ustr, u"ImapDialog"_ustr)
108
0
    , m_pCheckObj(nullptr)
109
0
    , m_aIMapItem(*this, *_pBindings)
110
0
    , m_xIMapWnd(new IMapWindow(_pBindings->GetActiveFrame(), m_xDialog.get()))
111
0
    , m_xTbxIMapDlg1(m_xBuilder->weld_toolbar(u"toolbar"_ustr))
112
0
    , m_xFtURL(m_xBuilder->weld_label(u"urlft"_ustr))
113
0
    , m_xURLBox(new SvtURLBox(m_xBuilder->weld_combo_box(u"url"_ustr)))
114
0
    , m_xFtText(m_xBuilder->weld_label(u"textft"_ustr))
115
0
    , m_xEdtText(m_xBuilder->weld_entry(u"text"_ustr))
116
0
    , m_xFtTarget(m_xBuilder->weld_label(u"targetft"_ustr))
117
0
    , m_xCbbTarget(m_xBuilder->weld_combo_box(u"target"_ustr))
118
0
    , m_xCancelBtn(m_xBuilder->weld_button(u"cancel"_ustr))
119
0
    , m_xStbStatus1(m_xBuilder->weld_label(u"statusurl"_ustr))
120
0
    , m_xStbStatus2(m_xBuilder->weld_label(u"statuspos"_ustr))
121
0
    , m_xStbStatus3(m_xBuilder->weld_label(u"statussize"_ustr))
122
0
    , m_xIMapWndWeld(new weld::CustomWeld(*m_xBuilder, u"container"_ustr, *m_xIMapWnd))
123
124
0
{
125
0
    m_xTbxIMapDlg1->insert_separator(4, u"sep1"_ustr);
126
0
    m_xTbxIMapDlg1->insert_separator(10, u"sep2"_ustr);
127
0
    m_xTbxIMapDlg1->insert_separator(15, u"sep3"_ustr);
128
0
    m_xTbxIMapDlg1->insert_separator(18, u"sel4"_ustr);
129
130
    //lock this down so it doesn't jump around in size
131
    //as entries are added later on
132
0
    TargetList aTmpList;
133
0
    SfxFrame::GetDefaultTargetList(aTmpList);
134
0
    for (const OUString & s : aTmpList)
135
0
        m_xCbbTarget->append_text(s);
136
0
    Size aPrefSize(m_xCbbTarget->get_preferred_size());
137
0
    m_xCbbTarget->set_size_request(aPrefSize.Width(), -1);
138
0
    m_xCbbTarget->clear();
139
140
0
    m_xIMapWnd->Show();
141
142
0
    m_pOwnData.reset(new IMapOwnData);
143
144
0
    m_xIMapWnd->SetInfoLink( LINK( this, SvxIMapDlg, InfoHdl ) );
145
0
    m_xIMapWnd->SetMousePosLink( LINK( this, SvxIMapDlg, MousePosHdl ) );
146
0
    m_xIMapWnd->SetGraphSizeLink( LINK( this, SvxIMapDlg, GraphSizeHdl ) );
147
0
    m_xIMapWnd->SetUpdateLink( LINK( this, SvxIMapDlg, StateHdl ) );
148
149
0
    m_xURLBox->connect_changed( LINK( this, SvxIMapDlg, URLModifyHdl ) );
150
0
    m_xURLBox->connect_focus_out( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
151
0
    m_xEdtText->connect_changed( LINK( this, SvxIMapDlg, EntryModifyHdl ) );
152
0
    m_xCbbTarget->connect_focus_out( LINK( this, SvxIMapDlg, URLLoseFocusHdl ) );
153
154
0
    m_xTbxIMapDlg1->connect_clicked( LINK( this, SvxIMapDlg, TbxClickHdl ) );
155
0
    OUString sSelect(u"TBI_SELECT"_ustr);
156
0
    m_xTbxIMapDlg1->set_item_active(sSelect, true);
157
0
    TbxClickHdl(sSelect);
158
159
0
    m_xStbStatus1->set_size_request(120, -1);
160
0
    const int nWidth = m_xStbStatus1->get_pixel_size(u" 9999,99 cm / 9999,99 cm "_ustr).Width();
161
0
    m_xStbStatus2->set_size_request(nWidth, -1);
162
0
    m_xStbStatus3->set_size_request(nWidth, -1);
163
164
0
    m_xFtURL->set_sensitive(false);
165
0
    m_xURLBox->set_sensitive(false);
166
0
    m_xFtText->set_sensitive(false);
167
0
    m_xEdtText->set_sensitive(false);
168
0
    m_xFtTarget->set_sensitive(false);
169
0
    m_xCbbTarget->set_sensitive(false);
170
0
    m_pOwnData->bExecState = false;
171
172
0
    m_pOwnData->aIdle.SetInvokeHandler( LINK( this, SvxIMapDlg, UpdateHdl ) );
173
174
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_ACTIVE"_ustr, false);
175
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_MACRO"_ustr, false );
176
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_PROPERTY"_ustr, false );
177
178
0
    m_xCancelBtn->connect_clicked(LINK(this, SvxIMapDlg, CancelHdl));
179
0
}
180
181
SvxIMapDlg::~SvxIMapDlg()
182
0
{
183
0
    m_xIMapWnd->SetUpdateLink( Link<GraphCtrl*,void>() );
184
0
    m_xIMapWnd.reset();
185
0
}
186
187
IMPL_LINK_NOARG(SvxIMapDlg, CancelHdl, weld::Button&, void)
188
0
{
189
0
    bool bRet = true;
190
191
0
    if ( m_xTbxIMapDlg1->get_item_sensitive(u"TBI_APPLY"_ustr) )
192
0
    {
193
0
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), u"svx/ui/querymodifyimagemapchangesdialog.ui"_ustr));
194
0
        std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog(u"QueryModifyImageMapChangesDialog"_ustr));
195
0
        const tools::Long nRet = xQBox->run();
196
197
0
        if( nRet == RET_YES )
198
0
        {
199
0
            SfxBoolItem aBoolItem( SID_IMAP_EXEC, true );
200
0
            GetBindings().GetDispatcher()->ExecuteList(SID_IMAP_EXEC,
201
0
                SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
202
0
                { &aBoolItem });
203
0
        }
204
0
        else if( nRet == RET_CANCEL )
205
0
            bRet = false;
206
0
    }
207
0
    else if( m_xIMapWnd->IsChanged() )
208
0
    {
209
0
        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), u"svx/ui/querysaveimagemapchangesdialog.ui"_ustr));
210
0
        std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog(u"QuerySaveImageMapChangesDialog"_ustr));
211
0
        const tools::Long nRet = xQBox->run();
212
213
0
        if( nRet == RET_YES )
214
0
            bRet = DoSave();
215
0
        else if( nRet == RET_CANCEL )
216
0
            bRet = false;
217
0
    }
218
219
0
    if (bRet)
220
0
        m_xDialog->response(RET_CANCEL);
221
0
}
222
223
// Enabled or disable all Controls
224
225
void SvxIMapDlg::SetExecState( bool bEnable )
226
0
{
227
0
    m_pOwnData->bExecState = bEnable;
228
0
}
229
230
const ImageMap& SvxIMapDlg::GetImageMap() const
231
0
{
232
0
    return m_xIMapWnd->GetImageMap();
233
0
}
234
235
void SvxIMapDlg::SetTargetList( const TargetList& rTargetList )
236
0
{
237
0
    m_xIMapWnd->SetTargetList( rTargetList );
238
239
0
    m_xCbbTarget->clear();
240
241
0
    for (const OUString & s : rTargetList)
242
0
        m_xCbbTarget->append_text(s);
243
0
}
244
245
void SvxIMapDlg::UpdateLink( const Graphic& rGraphic, const ImageMap* pImageMap,
246
                         const TargetList* pTargetList, void* pEditingObj )
247
0
{
248
0
    m_pOwnData->aUpdateGraphic = rGraphic;
249
250
0
    if ( pImageMap )
251
0
        m_pOwnData->aUpdateImageMap = *pImageMap;
252
0
    else
253
0
        m_pOwnData->aUpdateImageMap.ClearImageMap();
254
255
0
    m_pOwnData->pUpdateEditingObject = pEditingObj;
256
257
    // Delete UpdateTargetList, because this method can still be called several
258
    // times before the update timer is turned on
259
260
    // TargetList must be copied, since it is owned by the caller and can be
261
    // deleted immediately after this call the copied list will be deleted
262
    // again in the handler
263
0
    if( pTargetList )
264
0
        m_pOwnData->aUpdateTargetList = *pTargetList;
265
0
    else
266
0
        m_pOwnData->aUpdateTargetList.clear();
267
268
0
    m_pOwnData->aIdle.Start();
269
0
}
270
271
272
// Click-handler for ToolBox
273
274
IMPL_LINK(SvxIMapDlg, TbxClickHdl, const OUString&, rNewItemId, void)
275
0
{
276
0
    if (rNewItemId == "TBI_APPLY")
277
0
    {
278
0
        URLLoseFocusHdl(*m_xCbbTarget);
279
0
        SfxBoolItem aBoolItem( SID_IMAP_EXEC, true );
280
0
        GetBindings().GetDispatcher()->ExecuteList(SID_IMAP_EXEC,
281
0
            SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
282
0
            { &aBoolItem });
283
0
    }
284
0
    else if (rNewItemId == "TBI_OPEN")
285
0
        DoOpen();
286
0
    else if (rNewItemId == "TBI_SAVEAS")
287
0
        DoSave();
288
0
    else if (rNewItemId == "TBI_CLOSE")
289
0
        CancelHdl(*m_xCancelBtn);
290
0
    else if (rNewItemId == "TBI_SELECT")
291
0
    {
292
0
        SetActiveTool( rNewItemId );
293
0
        m_xIMapWnd->SetEditMode( true );
294
0
    }
295
0
    else if (rNewItemId == "TBI_RECT")
296
0
    {
297
0
        SetActiveTool( rNewItemId );
298
0
        m_xIMapWnd->SetObjKind( SdrObjKind::Rectangle );
299
0
    }
300
0
    else if (rNewItemId == "TBI_CIRCLE")
301
0
    {
302
0
        SetActiveTool( rNewItemId );
303
0
        m_xIMapWnd->SetObjKind( SdrObjKind::CircleOrEllipse );
304
0
    }
305
0
    else if (rNewItemId == "TBI_POLY")
306
0
    {
307
0
        SetActiveTool( rNewItemId );
308
0
        m_xIMapWnd->SetObjKind( SdrObjKind::Polygon );
309
0
    }
310
0
    else if (rNewItemId == "TBI_FREEPOLY")
311
0
    {
312
0
        SetActiveTool( rNewItemId );
313
0
        m_xIMapWnd->SetObjKind( SdrObjKind::FreehandFill );
314
0
    }
315
0
    else if (rNewItemId == "TBI_ACTIVE")
316
0
    {
317
0
        URLLoseFocusHdl(*m_xCbbTarget);
318
0
        bool bNewState = !m_xTbxIMapDlg1->get_item_active(rNewItemId);
319
0
        m_xTbxIMapDlg1->set_item_active(rNewItemId, bNewState);
320
0
        m_xIMapWnd->SetCurrentObjState( !bNewState );
321
0
    }
322
0
    else if (rNewItemId == "TBI_MACRO")
323
0
        m_xIMapWnd->DoMacroAssign();
324
0
    else if (rNewItemId == "TBI_PROPERTY")
325
0
        m_xIMapWnd->DoPropertyDialog();
326
0
    else if (rNewItemId == "TBI_POLYEDIT")
327
0
    {
328
0
        SetActiveTool( rNewItemId );
329
0
        m_xIMapWnd->SetPolyEditMode( m_xTbxIMapDlg1->get_item_active(rNewItemId) ? SID_BEZIER_MOVE : 0 );
330
0
    }
331
0
    else if (rNewItemId == "TBI_POLYMOVE")
332
0
    {
333
0
        SetActiveTool( rNewItemId );
334
0
        m_xIMapWnd->SetPolyEditMode( SID_BEZIER_MOVE );
335
0
    }
336
0
    else if (rNewItemId == "TBI_POLYINSERT")
337
0
    {
338
0
        SetActiveTool( rNewItemId );
339
0
        m_xIMapWnd->SetPolyEditMode( SID_BEZIER_INSERT );
340
0
    }
341
0
    else if (rNewItemId == "TBI_POLYDELETE")
342
0
    {
343
0
        SetActiveTool( rNewItemId );
344
0
        m_xIMapWnd->GetSdrView()->DeleteMarkedPoints();
345
0
    }
346
0
    else if (rNewItemId == "TBI_UNDO")
347
0
    {
348
0
        URLLoseFocusHdl(*m_xCbbTarget);
349
0
        m_xIMapWnd->GetSdrModel()->Undo();
350
0
    }
351
0
    else if (rNewItemId == "TBI_REDO")
352
0
    {
353
0
        URLLoseFocusHdl(*m_xCbbTarget);
354
0
        m_xIMapWnd->GetSdrModel()->Redo();
355
0
    }
356
0
}
357
358
void SvxIMapDlg::DoOpen()
359
0
{
360
0
    ::sfx2::FileDialogHelper aDlg(
361
0
        css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
362
0
        FileDialogFlags::NONE, m_xDialog.get());
363
364
0
    ImageMap        aLoadIMap;
365
0
    const OUString  aFilter(SvxResId(RID_SVXSTR_IMAP_ALL_FILTER));
366
367
0
    aDlg.AddFilter( aFilter, IMAP_ALL_TYPE );
368
0
    aDlg.AddFilter( IMAP_CERN_FILTER, IMAP_CERN_TYPE );
369
0
    aDlg.AddFilter( IMAP_NCSA_FILTER, IMAP_NCSA_TYPE );
370
0
    aDlg.AddFilter( IMAP_BINARY_FILTER, IMAP_BINARY_TYPE );
371
372
0
    aDlg.SetCurrentFilter( aFilter );
373
0
    aDlg.SetContext(sfx2::FileDialogHelper::ImageMap);
374
375
0
    if( aDlg.Execute() != ERRCODE_NONE )
376
0
        return;
377
378
0
    INetURLObject aURL( aDlg.GetPath() );
379
0
    DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
380
0
    std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
381
382
0
    if( pIStm )
383
0
    {
384
0
        aLoadIMap.Read( *pIStm, IMapFormat::Detect );
385
386
0
        if( pIStm->GetError() )
387
0
        {
388
0
            SfxErrorContext eEC(ERRCTX_ERROR, m_xDialog.get());
389
0
            ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
390
0
        }
391
0
        else
392
0
            m_xIMapWnd->SetImageMap( aLoadIMap );
393
0
    }
394
395
0
    m_xIMapWnd->Invalidate();
396
0
}
397
398
bool SvxIMapDlg::DoSave()
399
0
{
400
0
    ::sfx2::FileDialogHelper aDlg(
401
0
        css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE,
402
0
        FileDialogFlags::NONE, m_xDialog.get());
403
404
0
    const OUString    aBinFilter( IMAP_BINARY_FILTER );
405
0
    const OUString    aCERNFilter( IMAP_CERN_FILTER );
406
0
    const OUString    aNCSAFilter( IMAP_NCSA_FILTER );
407
0
    SdrModel*       pModel = m_xIMapWnd->GetSdrModel();
408
0
    const bool bChanged = pModel->IsChanged();
409
0
    bool            bRet = false;
410
411
0
    aDlg.AddFilter( aCERNFilter, IMAP_CERN_TYPE );
412
0
    aDlg.AddFilter( aNCSAFilter, IMAP_NCSA_TYPE );
413
0
    aDlg.AddFilter( aBinFilter, IMAP_BINARY_TYPE );
414
415
0
    aDlg.SetCurrentFilter( aCERNFilter );
416
0
    aDlg.SetContext(sfx2::FileDialogHelper::ImageMap);
417
418
0
    if( aDlg.Execute() == ERRCODE_NONE )
419
0
    {
420
0
        const OUString    aFilter( aDlg.GetCurrentFilter() );
421
0
        OUString          aExt;
422
0
        IMapFormat        nFormat;
423
424
0
        if ( aFilter == aBinFilter )
425
0
        {
426
0
            nFormat = IMapFormat::Binary;
427
0
            aExt = "sip";
428
0
        }
429
0
        else if ( aFilter == aCERNFilter )
430
0
        {
431
0
            nFormat = IMapFormat::CERN;
432
0
            aExt = "map";
433
0
        }
434
0
        else if ( aFilter == aNCSAFilter )
435
0
        {
436
0
            nFormat = IMapFormat::NCSA;
437
0
            aExt = "map";
438
0
        }
439
0
        else
440
0
        {
441
0
            return false;
442
0
        }
443
444
0
        INetURLObject aURL( aDlg.GetPath() );
445
446
0
        if( aURL.GetProtocol() == INetProtocol::NotValid )
447
0
        {
448
0
            OSL_FAIL( "invalid URL" );
449
0
        }
450
0
        else
451
0
        {
452
0
            if( aURL.getExtension().isEmpty() )
453
0
                aURL.setExtension( aExt );
454
455
0
            std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC ));
456
0
            if( pOStm )
457
0
            {
458
0
                m_xIMapWnd->GetImageMap().Write( *pOStm, nFormat );
459
460
0
                if( pOStm->GetError() )
461
0
                    ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
462
463
0
                pOStm.reset();
464
0
                pModel->SetChanged( bChanged );
465
0
                bRet = true;
466
0
            }
467
0
        }
468
0
    }
469
470
0
    return bRet;
471
0
}
472
473
void SvxIMapDlg::SetActiveTool(std::u16string_view rId)
474
0
{
475
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_SELECT"_ustr, rId == u"TBI_SELECT");
476
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_RECT"_ustr, rId == u"TBI_RECT");
477
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_CIRCLE"_ustr, rId == u"TBI_CIRCLE");
478
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_POLY"_ustr, rId == u"TBI_POLY");
479
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_FREEPOLY"_ustr, rId == u"TBI_FREEPOLY");
480
481
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_POLYINSERT"_ustr, rId == u"TBI_POLYINSERT");
482
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_POLYDELETE"_ustr, false);
483
484
0
    bool bMove = rId == u"TBI_POLYMOVE"
485
0
                || ( rId == u"TBI_POLYEDIT"
486
0
                && !m_xTbxIMapDlg1->get_item_active(u"TBI_POLYINSERT"_ustr)
487
0
                && !m_xTbxIMapDlg1->get_item_active(u"TBI_POLYDELETE"_ustr) );
488
489
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_POLYMOVE"_ustr, bMove );
490
491
0
    bool bEditMode = ( rId == u"TBI_POLYEDIT" )
492
0
                    || ( rId == u"TBI_POLYMOVE")
493
0
                    || ( rId == u"TBI_POLYINSERT")
494
0
                    || ( rId == u"TBI_POLYDELETE" );
495
496
0
    m_xTbxIMapDlg1->set_item_active(u"TBI_POLYEDIT"_ustr, bEditMode);
497
0
}
498
499
IMPL_LINK( SvxIMapDlg, InfoHdl, IMapWindow&, rWnd, void )
500
0
{
501
0
    const NotifyInfo&   rInfo = rWnd.GetInfo();
502
503
0
    if ( rInfo.bNewObj )
504
0
    {
505
0
        if (!rInfo.aMarkURL.isEmpty() && ( m_xURLBox->find_text(rInfo.aMarkURL) == -1))
506
0
            m_xURLBox->append_text(rInfo.aMarkURL);
507
508
0
        m_xURLBox->set_entry_text(rInfo.aMarkURL);
509
0
        m_xEdtText->set_text(rInfo.aMarkAltText);
510
511
0
        if ( rInfo.aMarkTarget.isEmpty() )
512
0
            m_xCbbTarget->set_entry_text( SELF_TARGET );
513
0
        else
514
0
            m_xCbbTarget->set_entry_text( rInfo.aMarkTarget );
515
0
    }
516
517
0
    if ( !rInfo.bOneMarked )
518
0
    {
519
0
        m_xTbxIMapDlg1->set_item_active(u"TBI_ACTIVE"_ustr, false);
520
0
        m_xTbxIMapDlg1->set_item_sensitive(u"TBI_ACTIVE"_ustr, false);
521
0
        m_xTbxIMapDlg1->set_item_sensitive(u"TBI_MACRO"_ustr, false);
522
0
        m_xTbxIMapDlg1->set_item_sensitive(u"TBI_PROPERTY"_ustr, false);
523
0
        m_xStbStatus1->set_label(OUString());
524
525
0
        m_xFtURL->set_sensitive(false);
526
0
        m_xURLBox->set_sensitive(false);
527
0
        m_xFtText->set_sensitive(false);
528
0
        m_xEdtText->set_sensitive(false);
529
0
        m_xFtTarget->set_sensitive(false);
530
0
        m_xCbbTarget->set_sensitive(false);
531
532
0
        m_xURLBox->set_entry_text( u""_ustr );
533
0
        m_xEdtText->set_text( u""_ustr );
534
0
    }
535
0
    else
536
0
    {
537
0
        m_xTbxIMapDlg1->set_item_sensitive(u"TBI_ACTIVE"_ustr, true);
538
0
        m_xTbxIMapDlg1->set_item_active(u"TBI_ACTIVE"_ustr, !rInfo.bActivated );
539
0
        m_xTbxIMapDlg1->set_item_sensitive(u"TBI_MACRO"_ustr, true);
540
0
        m_xTbxIMapDlg1->set_item_sensitive(u"TBI_PROPERTY"_ustr, true);
541
542
0
        m_xFtURL->set_sensitive(true);
543
0
        m_xURLBox->set_sensitive(true);
544
0
        m_xFtText->set_sensitive(true);
545
0
        m_xEdtText->set_sensitive(true);
546
0
        m_xFtTarget->set_sensitive(true);
547
0
        m_xCbbTarget->set_sensitive(true);
548
549
0
        m_xStbStatus1->set_label(rInfo.aMarkURL);
550
551
0
        if ( m_xURLBox->get_active_text() != rInfo.aMarkURL )
552
0
            m_xURLBox->set_entry_text( rInfo.aMarkURL );
553
554
0
        if ( m_xEdtText->get_text() != rInfo.aMarkAltText )
555
0
            m_xEdtText->set_text( rInfo.aMarkAltText );
556
557
0
        if ( rInfo.aMarkTarget.isEmpty() )
558
0
            m_xCbbTarget->set_entry_text( SELF_TARGET );
559
0
        else
560
0
            m_xCbbTarget->set_entry_text(  rInfo.aMarkTarget );
561
0
    }
562
0
}
563
564
IMPL_LINK( SvxIMapDlg, MousePosHdl, GraphCtrl*, pWnd, void )
565
0
{
566
0
    const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
567
0
    const Point& rMousePos = pWnd->GetMousePos();
568
0
    const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
569
0
    const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
570
571
0
    OUString aStr = GetUnitString( rMousePos.X(), eFieldUnit, cSep ) +
572
0
                    " / " + GetUnitString( rMousePos.Y(), eFieldUnit, cSep );
573
574
0
    m_xStbStatus2->set_label(aStr);
575
0
}
576
577
IMPL_LINK( SvxIMapDlg, GraphSizeHdl, GraphCtrl*, pWnd, void )
578
0
{
579
0
    const FieldUnit eFieldUnit = GetBindings().GetDispatcher()->GetModule()->GetFieldUnit();
580
0
    const Size& rSize = pWnd->GetGraphicSize();
581
0
    const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
582
0
    const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
583
584
0
    OUString aStr = GetUnitString( rSize.Width(), eFieldUnit, cSep ) +
585
0
                    " x " + GetUnitString( rSize.Height(), eFieldUnit, cSep );
586
587
0
    m_xStbStatus3->set_label(aStr);
588
0
}
589
590
void SvxIMapDlg::URLModify()
591
0
{
592
0
    NotifyInfo  aNewInfo;
593
594
0
    aNewInfo.aMarkURL = m_xURLBox->get_active_text();
595
0
    aNewInfo.aMarkAltText = m_xEdtText->get_text();
596
0
    aNewInfo.aMarkTarget = m_xCbbTarget->get_active_text();
597
598
0
    m_xIMapWnd->ReplaceActualIMapInfo( aNewInfo );
599
0
}
600
601
IMPL_LINK_NOARG(SvxIMapDlg, URLModifyHdl, weld::ComboBox&, void)
602
0
{
603
0
    URLModify();
604
0
}
605
606
0
IMPL_LINK_NOARG(SvxIMapDlg, EntryModifyHdl, weld::TextWidget&, void) { URLModify(); }
607
608
IMPL_LINK_NOARG(SvxIMapDlg, URLLoseFocusHdl, weld::Widget&, void)
609
0
{
610
0
    NotifyInfo        aNewInfo;
611
0
    const OUString    aURLText( m_xURLBox->get_active_text() );
612
0
    const OUString    aTargetText( m_xCbbTarget->get_active_text() );
613
614
0
    if ( !aURLText.isEmpty() )
615
0
    {
616
0
        OUString aBase = GetBindings().GetDispatcher()->GetFrame()->GetObjectShell()->GetMedium()->GetBaseURL();
617
0
        aNewInfo.aMarkURL = ::URIHelper::SmartRel2Abs( INetURLObject(aBase), aURLText, URIHelper::GetMaybeFileHdl(), true, false,
618
0
                                                        INetURLObject::EncodeMechanism::WasEncoded,
619
0
                                                        INetURLObject::DecodeMechanism::Unambiguous );
620
0
    }
621
0
    else
622
0
        aNewInfo.aMarkURL = aURLText;
623
624
0
    aNewInfo.aMarkAltText = m_xEdtText->get_text();
625
626
0
    if ( aTargetText.isEmpty() )
627
0
        aNewInfo.aMarkTarget = SELF_TARGET;
628
0
    else
629
0
        aNewInfo.aMarkTarget = aTargetText;
630
631
0
    m_xIMapWnd->ReplaceActualIMapInfo( aNewInfo );
632
0
}
633
634
IMPL_LINK_NOARG(SvxIMapDlg, UpdateHdl, Timer *, void)
635
0
{
636
0
    m_pOwnData->aIdle.Stop();
637
638
0
    if ( m_pOwnData->pUpdateEditingObject != m_pCheckObj )
639
0
    {
640
0
        if (m_xIMapWnd->IsChanged())
641
0
        {
642
0
            std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xDialog.get(), u"svx/ui/querysaveimagemapchangesdialog.ui"_ustr));
643
0
            std::unique_ptr<weld::MessageDialog> xQBox(xBuilder->weld_message_dialog(u"QuerySaveImageMapChangesDialog"_ustr));
644
0
            if (xQBox->run() == RET_YES)
645
0
            {
646
0
                DoSave();
647
0
            }
648
0
        }
649
650
0
        m_xIMapWnd->SetGraphic( m_pOwnData->aUpdateGraphic );
651
0
        m_xIMapWnd->SetImageMap( m_pOwnData->aUpdateImageMap );
652
0
        SetTargetList( m_pOwnData->aUpdateTargetList );
653
0
        m_pCheckObj = m_pOwnData->pUpdateEditingObject;
654
655
        // After changes => default selection
656
0
        m_xTbxIMapDlg1->set_item_active(u"TBI_SELECT"_ustr, true);
657
0
        m_xIMapWnd->SetEditMode( true );
658
0
    }
659
660
    // Delete the copied list again in the Update method
661
0
    m_pOwnData->aUpdateTargetList.clear();
662
663
0
    GetBindings().Invalidate( SID_IMAP_EXEC );
664
0
    m_xIMapWnd->QueueIdleUpdate();
665
0
}
666
667
IMPL_LINK( SvxIMapDlg, StateHdl, GraphCtrl*, pWnd, void )
668
0
{
669
0
    const SdrObject*    pObj = pWnd->GetSelectedSdrObject();
670
0
    const SdrModel*     pModel = pWnd->GetSdrModel();
671
0
    const SdrView*      pView = pWnd->GetSdrView();
672
0
    const bool          bPolyEdit = ( pObj != nullptr ) && dynamic_cast<const SdrPathObj*>( pObj) !=  nullptr;
673
0
    const bool          bDrawEnabled = !( bPolyEdit && m_xTbxIMapDlg1->get_item_active(u"TBI_POLYEDIT"_ustr) );
674
675
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_APPLY"_ustr, m_pOwnData->bExecState && pWnd->IsChanged() );
676
677
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_SELECT"_ustr, bDrawEnabled);
678
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_RECT"_ustr, bDrawEnabled);
679
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_CIRCLE"_ustr, bDrawEnabled);
680
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_POLY"_ustr, bDrawEnabled);
681
0
    m_xTbxIMapDlg1->set_item_sensitive(u"TBI_FREEPOLY"_ustr, bDrawEnabled);
682
683
    // BezierEditor State
684
0
    m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYEDIT"_ustr, bPolyEdit );
685
0
    m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYMOVE"_ustr, !bDrawEnabled );
686
0
    m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYINSERT"_ustr, !bDrawEnabled );
687
0
    m_xTbxIMapDlg1->set_item_sensitive( u"TBI_POLYDELETE"_ustr, !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
688
689
    // Undo/Redo
690
0
    m_xTbxIMapDlg1->set_item_sensitive( u"TBI_UNDO"_ustr, pModel->HasUndoActions() );
691
0
    m_xTbxIMapDlg1->set_item_sensitive( u"TBI_REDO"_ustr, pModel->HasRedoActions() );
692
693
0
    if ( bPolyEdit )
694
0
    {
695
0
        switch( pWnd->GetPolyEditMode() )
696
0
        {
697
0
            case SID_BEZIER_MOVE:
698
0
                m_xTbxIMapDlg1->set_item_active(u"TBI_POLYMOVE"_ustr, true);
699
0
                m_xTbxIMapDlg1->set_item_active(u"TBI_POLYINSERT"_ustr, false);
700
0
                break;
701
0
            case SID_BEZIER_INSERT:
702
0
                m_xTbxIMapDlg1->set_item_active(u"TBI_POLYINSERT"_ustr, true);
703
0
                m_xTbxIMapDlg1->set_item_active(u"TBI_POLYMOVE"_ustr, false);
704
0
                break;
705
0
            default:
706
0
                break;
707
0
        }
708
0
    }
709
0
    else
710
0
    {
711
0
        m_xTbxIMapDlg1->set_item_active( u"TBI_POLYEDIT"_ustr, false );
712
0
        m_xTbxIMapDlg1->set_item_active( u"TBI_POLYMOVE"_ustr, true);
713
0
        m_xTbxIMapDlg1->set_item_active( u"TBI_POLYINSERT"_ustr, false );
714
0
        pWnd->SetPolyEditMode( 0 );
715
0
    }
716
717
0
    m_xIMapWnd->QueueIdleUpdate();
718
0
}
719
720
SvxIMapDlg* GetIMapDlg()
721
0
{
722
0
    SfxChildWindow* pWnd = nullptr;
723
0
    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
724
0
    if (pViewFrm && pViewFrm->HasChildWindow(SvxIMapDlgChildWindow::GetChildWindowId()))
725
0
        pWnd = pViewFrm->GetChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
726
0
    return pWnd ? static_cast<SvxIMapDlg*>(pWnd->GetController().get()) : nullptr;
727
0
}
728
729
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */