1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/awt/XTopWindow.hpp>
21 #include <com/sun/star/frame/XDispatchRecorder.hpp>
23 #include <svl/eitem.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/weld.hxx>
26 #include <vcl/windowstate.hxx>
28 #include <recfloat.hxx>
29 #include <sfx2/strings.hrc>
30 #include <sfx2/sfxresid.hxx>
31 #include <sfx2/bindings.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/sfxsids.hrc>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/viewsh.hxx>
36 #include <svl/itemset.hxx>
38 SFX_IMPL_MODELESSDIALOGCONTOLLER(SfxRecordingFloatWrapper_Impl
, SID_RECORDING_FLOATWINDOW
);
40 SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl(vcl::Window
* pParentWnd
,
43 SfxChildWinInfo
const * pInfo
)
44 : SfxChildWindow(pParentWnd
, nId
)
47 SetController(std::make_shared
<SfxRecordingFloat_Impl
>(pBindings
, this, pParentWnd
->GetFrameWeld()));
49 SfxRecordingFloat_Impl
* pFloatDlg
= static_cast<SfxRecordingFloat_Impl
*>(GetController().get());
51 weld::Dialog
* pDlg
= pFloatDlg
->getDialog();
53 SfxViewFrame
*pFrame
= pBind
->GetDispatcher_Impl()->GetFrame();
54 vcl::Window
* pEditWin
= pFrame
->GetViewShell()->GetWindow();
56 Point aPos
= pEditWin
->OutputToScreenPixel( pEditWin
->GetPosPixel() );
60 vcl::WindowData aState
;
61 aState
.setMask(vcl::WindowDataMask::Pos
);
63 pDlg
->set_window_state(aState
.toStr());
65 pFloatDlg
->Initialize(pInfo
);
68 SfxRecordingFloatWrapper_Impl::~SfxRecordingFloatWrapper_Impl()
70 SfxBoolItem
aItem( FN_PARAM_1
, true );
71 css::uno::Reference
< css::frame::XDispatchRecorder
> xRecorder
= pBindings
->GetRecorder();
73 pBindings
->GetDispatcher()->ExecuteList(SID_STOP_RECORDING
,
74 SfxCallMode::SYNCHRON
, { &aItem
});
77 bool SfxRecordingFloatWrapper_Impl::QueryClose()
79 // asking for recorded macro should be replaced if index access is available!
81 css::uno::Reference
< css::frame::XDispatchRecorder
> xRecorder
= pBindings
->GetRecorder();
82 if ( xRecorder
.is() && !xRecorder
->getRecordedMacro().isEmpty() )
84 SfxRecordingFloat_Impl
* pFloatDlg
= static_cast<SfxRecordingFloat_Impl
*>(GetController().get());
85 weld::Dialog
* pDlg
= pFloatDlg
->getDialog();
87 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(pDlg
,
88 VclMessageType::Question
, VclButtonsType::YesNo
,
89 SfxResId(STR_MACRO_LOSS
)));
90 xQueryBox
->set_default_response(RET_NO
);
92 xQueryBox
->set_title(SfxResId(STR_CANCEL_RECORDING
));
93 bRet
= (xQueryBox
->run() == RET_YES
);
99 SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings
* pBind
, SfxChildWindow
* pChildWin
,
100 weld::Window
* pParent
)
101 : SfxModelessDialogController(pBind
, pChildWin
, pParent
, u
"sfx/ui/floatingrecord.ui"_ustr
,
102 u
"FloatingRecord"_ustr
)
103 , m_xToolbar(m_xBuilder
->weld_toolbar(u
"toolbar"_ustr
))
104 , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar
, *m_xBuilder
, pBind
->GetActiveFrame()))
105 , mnPostUserEventId(nullptr)
106 , m_bFirstActivate(true)
109 SfxBoolItem
aItem( SID_RECORDMACRO
, true );
110 GetBindings().GetDispatcher()->ExecuteList(SID_RECORDMACRO
,
111 SfxCallMode::SYNCHRON
, { &aItem
});
114 IMPL_LINK_NOARG(SfxRecordingFloat_Impl
, PresentParentFrame
, void*, void)
116 mnPostUserEventId
= nullptr;
117 css::uno::Reference
<css::awt::XTopWindow
> xTopWindow(m_xDispatcher
->GetFrame()->getContainerWindow(), css::uno::UNO_QUERY
);
119 xTopWindow
->toFront();
122 void SfxRecordingFloat_Impl::Activate()
124 SfxModelessDialogController::Activate();
125 if (!m_bFirstActivate
)
127 // tdf#147782 retain focus in launching frame on the first activate on automatically gaining focus on getting launched
128 m_bFirstActivate
= false;
129 mnPostUserEventId
= Application::PostUserEvent(LINK(this, SfxRecordingFloat_Impl
, PresentParentFrame
));
132 SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl()
134 if (mnPostUserEventId
)
135 Application::RemoveUserEvent(mnPostUserEventId
);
136 m_xDispatcher
->dispose();
139 void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo
& rInfo
) const
141 SfxModelessDialogController::FillInfo( rInfo
);
142 rInfo
.bVisible
= false;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */