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/frame/XDispatchRecorder.hpp>
22 #include <svl/eitem.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/weld.hxx>
25 #include <vcl/windowstate.hxx>
27 #include <recfloat.hxx>
28 #include <sfx2/strings.hrc>
29 #include <sfx2/sfxresid.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/sfxsids.hrc>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/viewsh.hxx>
36 SFX_IMPL_MODELESSDIALOGCONTOLLER(SfxRecordingFloatWrapper_Impl
, SID_RECORDING_FLOATWINDOW
);
38 SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl(vcl::Window
* pParentWnd
,
41 SfxChildWinInfo
const * pInfo
)
42 : SfxChildWindow(pParentWnd
, nId
)
45 SetController(std::make_shared
<SfxRecordingFloat_Impl
>(pBindings
, this, pParentWnd
->GetFrameWeld()));
47 SfxRecordingFloat_Impl
* pFloatDlg
= static_cast<SfxRecordingFloat_Impl
*>(GetController().get());
49 weld::Dialog
* pDlg
= pFloatDlg
->getDialog();
51 SfxViewFrame
*pFrame
= pBind
->GetDispatcher_Impl()->GetFrame();
52 vcl::Window
* pEditWin
= pFrame
->GetViewShell()->GetWindow();
54 Point aPos
= pEditWin
->OutputToScreenPixel( pEditWin
->GetPosPixel() );
58 WindowStateData aState
;
59 aState
.SetMask(WindowStateMask::Pos
);
60 aState
.SetX(aPos
.X());
61 aState
.SetY(aPos
.Y());
62 pDlg
->set_window_state(aState
.ToStr());
64 pFloatDlg
->Initialize(pInfo
);
67 SfxRecordingFloatWrapper_Impl::~SfxRecordingFloatWrapper_Impl()
69 SfxBoolItem
aItem( FN_PARAM_1
, true );
70 css::uno::Reference
< css::frame::XDispatchRecorder
> xRecorder
= pBindings
->GetRecorder();
72 pBindings
->GetDispatcher()->ExecuteList(SID_STOP_RECORDING
,
73 SfxCallMode::SYNCHRON
, { &aItem
});
76 bool SfxRecordingFloatWrapper_Impl::QueryClose()
78 // asking for recorded macro should be replaced if index access is available!
80 css::uno::Reference
< css::frame::XDispatchRecorder
> xRecorder
= pBindings
->GetRecorder();
81 if ( xRecorder
.is() && !xRecorder
->getRecordedMacro().isEmpty() )
83 SfxRecordingFloat_Impl
* pFloatDlg
= static_cast<SfxRecordingFloat_Impl
*>(GetController().get());
84 weld::Dialog
* pDlg
= pFloatDlg
->getDialog();
86 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(pDlg
,
87 VclMessageType::Question
, VclButtonsType::YesNo
,
88 SfxResId(STR_MACRO_LOSS
)));
89 xQueryBox
->set_default_response(RET_NO
);
91 xQueryBox
->set_title(SfxResId(STR_CANCEL_RECORDING
));
92 bRet
= (xQueryBox
->run() == RET_YES
);
98 SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings
* pBind
, SfxChildWindow
* pChildWin
,
99 weld::Window
* pParent
)
100 : SfxModelessDialogController(pBind
, pChildWin
, pParent
, "sfx/ui/floatingrecord.ui",
102 , m_xToolbar(m_xBuilder
->weld_toolbar("toolbar"))
103 , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar
, *m_xBuilder
, pBind
->GetActiveFrame()))
106 SfxBoolItem
aItem( SID_RECORDMACRO
, true );
107 GetBindings().GetDispatcher()->ExecuteList(SID_RECORDMACRO
,
108 SfxCallMode::SYNCHRON
, { &aItem
});
111 SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl()
113 m_xDispatcher
->dispose();
116 void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo
& rInfo
) const
118 SfxModelessDialogController::FillInfo( rInfo
);
119 rInfo
.bVisible
= false;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */